java - How to monitor if my App is paused or resumed? -
i have android app want track when app paused or resumed.
paused: user pressed home button , app still running in background.
resumed: app runs in background , user opens app.
how can being notified when app paused/resumed?
paused: user pressed home button , app still running in background.
i going guess initial state 1 of activities in foreground @ time home button pressed.
on whole, there no notion in android of "app" being in foreground or background, though use phrasing shorthand other scenarios.
whatever activity in foreground called onpause()
, onstop()
when user presses home, events called in many other scenarios (e.g., user presses back). onuserleavehint()
called when user presses home not back, onuserleavehint()
not called in other scenarios (e.g., incoming call screen takes on foreground). whether onuserleavehint()
meet requirements, cannot say.
resumed: app runs in background , user opens app.
onstart()
, onresume()
, @ minimum, called on activity takes on foreground. called @ other times too, such when activity coming onto screen first time. there onrestart()
, called if activity being started after having been stopped (i.e., after prior onstop()
call), weed out newly-created-activity scenario. however, onrestart()
called in other scenarios well, such part of configuration change (e.g., screen rotation).
in general, seeking not part of android architecture. may need approach problem in other way.
Comments
Post a Comment