Android : Kill all activities when app is in background

on Wednesday, October 8, 2014


When my app goes to background and i receive a broadcast that my app is in inconsistent state and i want to ensure that the next time my app comes to foreground, i launch the Launcher(or root) activity. To do this I have the following approaches,




  1. All my activities derive from a base . When resuming check for the state of app in base. Launch Root activity if the state is inconsistent. Problem : App resume should be fast and checking state is a db call. Also there would be a visible flip to Root activity which i want to avoid.




  2. Catch hold of foreground activity in broadcast receiver, clear the task and launch main activity. Problem: I have to maintain a reference to top activity like described here.



  3. Kill the process in broadcast receiver when inconsistent state is reached.


What is the best approach?


0 comments:

Post a Comment