0

I have read both solutions here:

Prevent Activity Stack from being Restored?

But I hope there is a more elegant way to solve this.

Here is where my problem originates. I have an Activity that has a View Pager with Fragments Those fragments are inner classes and for some reason inner Fragments should be static. The fragments however, use a lot of stuff from the parent Activity, that is not static, and cannot be accessed from a static context. I tried passing them as arguments, but one of the arguments is the ViewPager itself and it cannot be serialized or accessed from a static context. If the app has been idle for hours, the Activity is recreated instead of started fresh, and the non-static inner class Fragment crashes.

My activity does not need to remember its state from 5 hours ago. I want it to not be restored whenever the app is brought back to foreground again.

Community
  • 1
  • 1
Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180

1 Answers1

0

I think I found the solution, it is so simple! (a bit hacky though)

@Override
protected void onSaveInstanceState(Bundle outState) {

}

No call to super, so the OS has no information to use when attempting to restore the activity state, so it builds it anew altoghether.

Kaloyan Roussev
  • 14,515
  • 21
  • 98
  • 180