Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After much trial and error and many readings, I finally found a way to sort of solve my problem. </p> <p>From what I understand, this problem will occur due to the Activity's life cycle. The comment by Tseng in this forum was quite comprehensive: <a href="http://forum.unity3d.com/threads/127794-Android-Apps-crashing-on-resume" rel="nofollow">http://forum.unity3d.com/threads/127794-Android-Apps-crashing-on-resume</a></p> <p>It seems that during the time when other applications are invoked when a certain activity is <code>onPause/onStop</code>, Android might free up some of its memory the activity is currently holding on to if there is insufficient memory required. In this case, all the current objects or variable the paused activity is having will be destroyed. Thus, when the activity is back on focus, the <code>onCreate</code> is actually invoked again. Thus, the activity will have no idea which fragment I am currently require. </p> <p>However, I realized that it will always call the saveInstanceState which is essentially a bundle object. So I did the following:</p> <p>onSaveInstanceState method</p> <pre><code> @Override public void onSaveInstanceState(Bundle bundle) { //activityFrag is a string object that tells me which fragment i am in currently bundle.putString("statusCheck", activityFrag); } </code></pre> <p>onCreate method</p> <pre><code>if (savedInstanceState != null) { getSupportFragmentManager().popBackStack(null, getSupportFragmentManager().POP_BACK_STACK_INCLUSIVE); //return; statusCheck = savedInstanceState.getString("statusCheck"); } else { statusCheck = b.getString("statusCheck"); } </code></pre> <p>What I have done is to remove all the fragments I have stacked thus far to remove any issues where there is missing information needed. So this is like starting anew again. The status check just determine which fragment the user has last visited.</p> <p>After much testing, it seems like it does solve my problem. though I wouldn't say it is perfect. One of the main downfall I have is that whenever I change my fragment, I have to update and change my statusCheck to make sure the correct fragment will be called. However, I have to admit this way is a little unorthodox and might not be very correct.</p> <p>If any of you have any better ideas, please feel free to share! </p>
 

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