0

I have a MainActivity (MA) and a DetailActivity (DA), where MA contains a CursorLoader displayed in a grid (RecyclerView). If the app goes to the background (and is possibly destroyed) and then restarted/restored, then MA is always re-initialized on restart (grid has all data).

DA, on the other hand, contains a FragmentStatePagerAdapter, which gets the same cursor (from MA) and creates a number of "pages" (Fragments) in a ViewPager. Each such PageFragment gets one row of the cursor in a Bundle (arguments) for display.

If the app goes to the background (but not destroyed) while showing DA, then the PageFragment is restored nicely (with data). But if the app ends up being destroyed after showing DA, then the app is restored with only a blank fragment (no data).

How can I fix this? What do I look for? Is it that my DA (or probably PageFragment) is not saving the state on becoming inactive, or is it a matter of handling the restore more properly?

I'm assuming it's the PageFragment, and presumably not the DetailActivity, that has to save and/or restore state more properly. I'm asking because maybe there is a very obvious explanation for this type of scenario, or at least I might get some clues on what to check.

Jon
  • 9,156
  • 9
  • 56
  • 73
joakimk
  • 822
  • 9
  • 26
  • How is it getting into the DetailActivity on launch if the process was destroyed? If the process was destroyed, then it should go to the launcher activity, which I assume is MainActivity. – Daniel Nugent Oct 05 '17 at 17:53
  • I see. So, then it hasn't been destroyed. But the point is, if I move it to the background and leave it there for a sufficiently long time (more than a few minutes) then I get the blank screen (if I left it within the DetailActivity). Stopped is maybe the right state – joakimk Oct 05 '17 at 20:11
  • In onResume() of DetailActivity, log the contents of the data source for what should be displayed. – Daniel Nugent Oct 05 '17 at 20:14
  • But since DetailActivity takes the entire cursor (from mainactivity) to create the Viewpager, onResume should do what? Should it recreate all pages, and then take the user to the specific page (position) the user last viewed? I've been thinking the blank page I'm seeing on restart is actually the DetailActivity, and not the last viewed PageFragment at all! Interesting. I'll check that the cursor is still available, and not empty. Things like that :-) – joakimk Oct 05 '17 at 20:22

0 Answers0