我在处理k-9邮件。所有的设置步骤都完美地完成了,但根据我的要求,我希望多个帐户打开与多个凭证存在。我尝试使用不同线程的for循环,但它只执行了最后一次登录!
我试着这样做,但它不起作用。
任何人请给我建议...
gmail_creds= Helpers.getArrayList(WelcomeMessage.this,"email_creds");
for( int i=0;i<gmail_creds.size();i++){
final int j=i;
//k
new Thread(new Runnable() {
public void run(){
Helpers.saveStringInSP(WelcomeMessage.this,"userEmail", gmail_creds.get(j).userEmail);
Helpers.saveStringInSP(WelcomeMessage.this,"userPassword",gmail_creds.get(j).userPassword);
AccountSetupBasics.actionNewAccount(WelcomeMessage.this);
}
}).start();
}发布于 2019-03-11 21:05:17
尝试以下操作,并让我知道。
注意:我还没有完全测试它。
gmail_creds= Helpers.getArrayList(WelcomeMessage.this,"email_creds");
List<Thread> threads = new ArrayList<Thread>();
for( int i = 0; i < gmail_creds.size(); i++){
final int j = i;
Thread t = new Thread(new Runnable() {
public void run(){
Helpers.saveStringInSP(WelcomeMessage.this,"userEmail", gmail_creds.get(j).userEmail);
Helpers.saveStringInSP(WelcomeMessage.this,"userPassword",gmail_creds.get(j).userPassword);
AccountSetupBasics.actionNewAccount(WelcomeMessage.this);
}
})
t.start();
threads.add(t);
}
// Let all threads to finish execution prior continuing main thread.
try {
for(Threat t: threads){
t.join();
}
} catch(InterruptedException ie){
ie.printStackTrace();
}https://stackoverflow.com/questions/55101838
复制相似问题