Fix state recognition on restart.
This commit is contained in:
@ -24,7 +24,7 @@ public class MainActivity extends I2PActivityBase {
|
||||
private Runnable _updater;
|
||||
private Runnable _oneShotUpdate;
|
||||
private String _savedStatus;
|
||||
private boolean _keep;
|
||||
private boolean _keep = true;
|
||||
|
||||
|
||||
protected static final String PROP_NEW_INSTALL = "i2p.newInstall";
|
||||
@ -272,13 +272,16 @@ public class MainActivity extends I2PActivityBase {
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
RouterContext ctx = getRouterContext();
|
||||
// RouterService svc = _routerService;
|
||||
_keep = Util.isConnected(this) && ctx != null;
|
||||
Util.e("*********************************************************");
|
||||
Util.e("Back pressed, Keep? " + _keep);
|
||||
Util.e("*********************************************************");
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
// RouterContext ctx = getRouterContext();
|
||||
super.onDestroy();
|
||||
if (!_keep) {
|
||||
Thread t = new Thread(new KillMe());
|
||||
@ -288,6 +291,9 @@ public class MainActivity extends I2PActivityBase {
|
||||
|
||||
private class KillMe implements Runnable {
|
||||
public void run() {
|
||||
Util.e("*********************************************************");
|
||||
Util.e("KillMe started!");
|
||||
Util.e("*********************************************************");
|
||||
try {
|
||||
Thread.sleep(500); // is 500ms long enough?
|
||||
} catch (InterruptedException ex) {
|
||||
|
@ -28,8 +28,8 @@ import net.i2p.util.OrderedProperties;
|
||||
*/
|
||||
public class RouterService extends Service {
|
||||
|
||||
// These states persist even if we died... Yuck, it causes issues.
|
||||
public enum State {
|
||||
|
||||
INIT, WAITING, STARTING, RUNNING,
|
||||
// unplanned (router stopped itself), next: killSelf()
|
||||
STOPPING, STOPPED,
|
||||
@ -80,8 +80,11 @@ public class RouterService extends Service {
|
||||
Intent intent = new Intent(this, RouterService.class);
|
||||
intent.putExtra(EXTRA_RESTART, true);
|
||||
onStartCommand(intent, 12345, 67890);
|
||||
} else if(lastState == State.MANUAL_QUITTING || lastState == State.MANUAL_QUITTED) {
|
||||
stopSelf(); // Die.
|
||||
} else if(lastState == State.MANUAL_QUITTING) {
|
||||
synchronized(_stateLock) {
|
||||
setState(State.MANUAL_QUITTED);
|
||||
stopSelf(); // Die.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -657,14 +660,15 @@ public class RouterService extends Service {
|
||||
|| _state == State.STOPPING) {
|
||||
Util.i(this + " died of unknown causes");
|
||||
setState(State.STOPPED);
|
||||
stopForeground(true);
|
||||
stopSelf();
|
||||
} else if(_state == State.MANUAL_QUITTING) {
|
||||
setState(State.MANUAL_QUITTED);
|
||||
stopForeground(true);
|
||||
stopSelf();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
stopForeground(true);
|
||||
_statusBar.remove();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user