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!!!