QUESTION 1: Since it seems that the layout was not being completely removed I decided to try removing all the listeners to all the child items in each fragment's onDestroy
. I ended up finding the method removeAllViewsInLayout()
and decided to try the following code:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
container.removeAllViewsInLayout();
return inflater.inflate(R.layout.welcome_select_cabinet, container, false);
}
This went into each fragment so that before the layout was inflated for that layout the ViewGroup's child items would be cleared. This solved the issue of the "clicking through" to the previous fragment's items.
QUESTION 2: I have added the following immediately after setContentView()
in my "Main" activity:
getFragmentManager().popBackStack();
And then when I add the first fragment in the onCreate
of "Main", I changed the following:
Welcome welcomeFragment = new Welcome();
getFragmentManager().beginTransaction().add(R.id.parent_container, welcomeFragment, "welcomeSelect").commit();
to this:
WelcomeSelectCabinet welcomeSelection = new WelcomeSelectCabinet();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.add(R.id.parent_container, welcomeSelection, "welcomeSelect");
transaction.addToBackStack(null);
transaction.commit();
Now if I wait for about 2 seconds after a reboot, and then start to use the app, I will not encounter any errors. But if I use the app immediately then there are the same errors as before until I reboot again and wait for 2 seconds.
EDIT: I added a 5 second load screen in order to account for the ~2 second "loading" and that seems to have fixed the problem on the Nexus 7 but not the Galaxy Tab 2. I changed the 5 seconds to 10 seconds since the Galaxy Tab 2 seems to take about twice as long to boot and this seemed to have fixed the problem.
EDIT: To make loading more compatible, I was able to tie it into the BOOT_COMPLETED
receiver and set a Boolean that is stored in SharedPreferences
that will determine which fragments to load based on the value, which is reset on the SHUTDOWN
BroadcastReceiver.