[Q] Navigating My Activity Hierarchy - Troubleshooting

Search This thread

Nsouth

New member
Apr 28, 2014
1
0
See the example hierarchy attached. There is a flow up and down. Using the app would go something like this:

Select Team 1 on the Home activity --> Activity A inflates based on the selection.
Select Player 2 on Activity A --> Activity B inflates based on the selection.
Select to Add a Stat on Activity B --> Activity C inflates and allows a stat to be added.

User returns to Activity B, which must maintain the Player 2 context and update based on C.
User returns to Activity A, which must maintain the Team 1 context and updated based on B.
User returns to Home, which must update based on A.

BBk1V.png

My question is how to update an activity based on its child while maintaining the context supplied by its parent.

For example, let's focus on Activity B. It knows to inflate for Player 1 because this info was passed from Activity A in an intent.

  • If I were to go to Activity C and press Back, B wouldn't update.
  • If I were to go to C and press Up, B would crash because it would try to make a new instance and wouldn't know what player to inflate (defined in onCreate()).
I tried declaring B with a "singleTop" launchMode, but then it just restarts and doesn't update based on C's info. Based on my limited experience/research, I see the following options.

  1. Store an Activity's inflater variables as static (so they won't be "lost" when creating a new instance)
  2. Initiate my view inflation (via Fragment) in the Activity's onStart() method so that it would refresh when Restarting. (Would this help? What about the fact that all of my inflation happens inside of a fragment? I fear the Lifecycle gods.)

I'm new to a lot of this and would appreciate any help. Thanks!