Clear all activities when showing startup failure notification.

This commit is contained in:
akwizgran
2014-02-05 16:20:07 +00:00
parent cd49254559
commit 765340c34b
2 changed files with 20 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import static java.util.logging.Level.INFO;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
@@ -37,6 +38,7 @@ public class BriarService extends RoboService {
private static final Logger LOG = private static final Logger LOG =
Logger.getLogger(BriarService.class.getName()); Logger.getLogger(BriarService.class.getName());
private final AtomicBoolean created = new AtomicBoolean(false);
private final Binder binder = new BriarBinder(); private final Binder binder = new BriarBinder();
@Inject private DatabaseConfig databaseConfig; @Inject private DatabaseConfig databaseConfig;
@@ -52,6 +54,11 @@ public class BriarService extends RoboService {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
if(LOG.isLoggable(INFO)) LOG.info("Created"); if(LOG.isLoggable(INFO)) LOG.info("Created");
if(created.getAndSet(true)) {
if(LOG.isLoggable(INFO)) LOG.info("Already created");
stopSelf();
return;
}
if(databaseConfig.getEncryptionKey() == null) { if(databaseConfig.getEncryptionKey() == null) {
if(LOG.isLoggable(INFO)) LOG.info("No database key"); if(LOG.isLoggable(INFO)) LOG.info("No database key");
stopSelf(); stopSelf();
@@ -92,6 +99,11 @@ public class BriarService extends RoboService {
Object o = getSystemService(Context.NOTIFICATION_SERVICE); Object o = getSystemService(Context.NOTIFICATION_SERVICE);
NotificationManager nm = (NotificationManager) o; NotificationManager nm = (NotificationManager) o;
nm.notify(FAILURE_NOTIFICATION_ID, b.build()); nm.notify(FAILURE_NOTIFICATION_ID, b.build());
// Bring HomeScreenActivity to the front to clear all other activities
Intent i = new Intent(this, HomeScreenActivity.class);
i.setFlags(FLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TOP);
i.putExtra("briar.STARTUP_FAILED", true);
startActivity(i);
} }
@Override @Override

View File

@@ -53,8 +53,14 @@ public class HomeScreenActivity extends BriarActivity {
@Override @Override
public void onCreate(Bundle state) { public void onCreate(Bundle state) {
super.onCreate(state); super.onCreate(state);
long handle = getIntent().getLongExtra("briar.LOCAL_AUTHOR_HANDLE", -1); Intent i = getIntent();
if(handle == -1) { boolean failed = i.getBooleanExtra("briar.STARTUP_FAILED", false);
long handle = i.getLongExtra("briar.LOCAL_AUTHOR_HANDLE", -1);
if(failed) {
finish();
if(LOG.isLoggable(INFO)) LOG.info("Exiting");
System.exit(0);
} else if(handle == -1) {
// The activity has been launched before // The activity has been launched before
showButtons(); showButtons();
} else { } else {