avoid unnecessary thread creation

This commit is contained in:
iNPUTmice 2015-03-05 15:46:33 +01:00
parent c5230e081c
commit f25a824610
3 changed files with 29 additions and 17 deletions

View File

@ -1136,7 +1136,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
account.initOtrEngine(this);
databaseBackend.createAccount(account);
this.accounts.add(account);
this.reconnectAccount(account, false);
this.reconnectAccountInBackground(account);
updateAccountUi();
}
@ -1972,10 +1972,7 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
}
public void reconnectAccount(final Account account, final boolean force) {
new Thread(new Runnable() {
@Override
public void run() {
synchronized (account) {
if (account.getXmppConnection() != null) {
disconnect(account, force);
}
@ -1991,6 +1988,14 @@ public class XmppConnectionService extends Service implements OnPhoneContactsLoa
account.setXmppConnection(null);
}
}
}
public void reconnectAccountInBackground(final Account account) {
new Thread(new Runnable() {
@Override
public void run() {
reconnectAccount(account,false);
}
}).start();
}

View File

@ -65,7 +65,7 @@ public class SettingsActivity extends XmppActivity implements
for (Account account : xmppConnectionService.getAccounts()) {
account.setResource(resource);
if (!account.isOptionSet(Account.OPTION_DISABLED)) {
xmppConnectionService.reconnectAccount(account, false);
xmppConnectionService.reconnectAccountInBackground(account);
}
}
}

View File

@ -242,6 +242,13 @@ public class XmppConnection implements Runnable {
@Override
public void run() {
try {
if (socket != null) {
socket.close();
}
} catch (final IOException ignored) {
}
connect();
}