I have an application that accesses a server. I have many activities that access the server for data. At various points in the application, I do a simple check to verify two things, 1) There is internet connectivity and 2) The server is not in maintenance mode or down.. If it is, I display an Activity detailing why and when the server will be back up.
When a user clicks back in this “Server is down” Activity, I need to exit the application. I have tried the following code/intent to call the “Server Down” activity but it doesn’t work.
Intent i = new Intent(this, ServerMaintenanceActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
I have looked all over and this is a very common problem faced with people typically on login/logout screens. None of the solutions I find works for me. I know it’s possible because I have apps that do just this for example Spotify.
Any ideas? Thanks.
Whenever you start an activity, you can create new
ResultReceiverthen put it into a list, in a global helper class. Then, in your notification activity (telling the user “Server is down”), overrideonDestroy()and send request to finish others.For example:
Helperclass:Other activities:
Notification activity: