Skip to content

Instantly share code, notes, and snippets.

@tomwis
Last active September 10, 2017 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomwis/285404c8a932e6517a88ab73072d1498 to your computer and use it in GitHub Desktop.
Save tomwis/285404c8a932e6517a88ab73072d1498 to your computer and use it in GitHub Desktop.
List<Type> _fragmentsQueue;
bool _instanceStateSaved;
protected override void OnSaveInstanceState(Bundle outState)
{
_instanceStateSaved = true; // Zaznaczamy, że nie możemy już dodawać fragmentów
base.OnSaveInstanceState(outState);
}
protected override void OnPostResume()
{
base.OnPostResume();
_instanceStateSaved = false; // Aplikacja została już wznowiona, więc możemy znowu dodawać fragmenty
// Sprawdzamy, czy mamy coś w kolejce, a jeśli tak, to dodajemy te fragmenty do widoku
for(int i = 0; i < _fragmentsQueue.Count;)
{
AddFragment(_fragmentsQueue[i]);
_fragmentsQueue.RemoveAt(0);
}
}
protected override void OnStop()
{
base.OnStop();
if (_instanceStateSaved)
{
_fragmentsQueue.Add(typeof(MyFragment));
}
else
{
AddFragment(typeof(MyFragment));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment