0

I have an app with many Activities, A (the main), B, C, D, E and a Service running in the background... My app is a client connected to a server. At a certain point the server tells the client to log out, the service receives the message and now I should logout and close the app. I tried to start the Activity A from the service and overriding in A the onNewIntent callback but it is never fired. The problem is that I'd like a way to kill the app whatever activity I'm in. I thought starting a fresh activity (with CLEAR_TOP) and overriding its onNeIntent would have been but the method is never called. Should I use broadcast and a receiver in each activity? What is the correct pattern to handle this situation?

Service when it receives the message:

Intent intent = new Intent(this, HomePage.class);
Bundle b = new Bundle();
b.putBoolean("VIMSANDROID_SLOGGAUTENTE", true);
intent.putExtras(b);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

A (the main):

@Override
public void onNewIntent(Intent i)
{
    finish();
startActivity(i);
}

Thanks!!!

Luigi Tiburzi
  • 4,265
  • 7
  • 32
  • 43
  • You shouldn't really kill an app - rather, redirect any further usage to a login Activity, which the user can either operate or leave in favor of something else on the phone. – Chris Stratton May 21 '13 at 14:39

1 Answers1

0

calling finish() only kills the particular activity in which it is called. if you want to kill your app then try this one.

System.runFinalizersOnExit(true); //depricated now

OR

android.os.Process.killProcess(android.os.Process.myPid());

Syed_Adeel
  • 430
  • 5
  • 14
  • Well my process has a service and the stack of activities, kill process doesn't allow me to exit properly... – Luigi Tiburzi May 22 '13 at 13:08
  • then i dont think there is any other way because by what ever mean your app is quit, your stack and service will be destroyed . if you want to kill them properly before app exit then do it by your application code then kill the processes. – Syed_Adeel May 22 '13 at 13:17
  • I need to pass via the activity A, that's why I'm trying to use onNewIntent() – Luigi Tiburzi May 22 '13 at 13:21