Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Indeed a very good question which I try to puzzle out myself.</p> <p>I even wonder What's the difference between killing an app and restarting the phone. <br>If a user manually kills an app or opens 20 other apps, he'd probably want the app to start from the beginning. Why Android aren't restoring state after phone restart?</p> <p>Also, I see that when an app is killed (by the system), global variables turn to null upon activity reinitiating. This kind of breaks the concept of Java. If you have some kind of state in the application and the application erases it, I would expect the application to restart.</p> <p>The solution I propose:</p> <pre><code>1. Handle the case of a state problem: Initiate a simple state (new Object()) as a global variable. For each Activity, in the methods onCreate/Start/Resume check that the state is null. If it's null launch the first activity with 'Intent.FLAG_ACTIVITY_CLEAR_TOP' - as if the application is relaunched. 2. Try not to use global variables - Always put data in the intent. 3. Lazy load global variables - If you do want to use global data, don't count on one time initialization. Lazy load them 'if (A.MY_DATA == null) {A.MY_DATA = new ...}' - Don't forget to do it in the background if it will take a long time (AsyncTask). Loading partial state needs to be done carefully because it may not comply to other loaded state objects. </code></pre> <p>The downside of the first point is that the state problem handling needs to be done on every Activity (AOP is not yet implemented in Android).</p> <p>Hope that helped.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload