I have some activities basically set up as shown below (clicks on are ListViews).
Parent class method to go to MyChild1
public void onItemClick(int pos){
Intent i = new Intent(this, MyChild1.class);
i.putExtra("KEY1", myAdapter.getItem(pos).getId());
startActivity(i);
}
MyChild1 class method to go to MyChild2
public void onItemClick(int pos){
Intent i = new Intent(this, MyChild2.class);
i.putExtra("KEY2", myAdapter2.getItem(pos).getId());
startActivity(i);
}
So you see that I have a parent, a child, and a grandchild activity. The child inflates based on the id provided by the parent and the grandchild inflates based on the id of the child. This works fine. However, when I use up navigation from the grandchild back to the child, it no longer has the id it needs from the parent to properly inflate. I need to support up navigation because the child can change based on actions in the grandchild.
I could pass the parent's id all the way down to the grandchild activity, but I don't know how to pass it back up. How can I handle this?
Edit: More code for context.
Here is my activity's onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_course);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new CourseActivityFragment()).commit();
Intent intent = getIntent();
courseId = intent.getIntExtra(MainFragment.COURSE_ID, 0);
System.out.println("the saved state was null");
// The above prints, so I know it enters this if statement
} else {
courseId = savedInstanceState.getInt(COURSE_ID);
}
}
And here is my onSaveInstanceState
@Override
public void onSaveInstanceState(Bundle savedInstanceState){
// Save current CourseId
savedInstanceState.putInt(COURSE_ID, courseId);
// Call superclass to save view hierarchy state
super.onSaveInstanceState(savedInstanceState);
}