java - Determine whether onPause() was fired by user navigation or by my activity launching another one -
how can determine whether onpause()
fired because activity launched new 1 (e.g. photo picker intent) or because user navigated away activity (e.g. pressing home)?
a simple solution have state
variable in activity
fixed values:
final static int running = 0; final static int called_something = 1; int state = running:
then, whenever launch activity:
state = called_something;
and when returns:
state = running;
and in onpause()
:
switch(state) { case running: // stuff if home etc pressed break; case called_something: // other stuff break; }
obviously, can extend further scenarios. may wish catch onbackpressed()
make sure handle situation understanding possible.
Comments
Post a Comment