Wednesday, January 18, 2012

Re: [android-developers] Detecting exit and open of an app with multiple activities

You can use onUserLeaveHint() to detect when a user is leaving your
activity in a way that might suggest they are leaving the whole app,
but it doesn't cover everything (e.g., incoming phone calls). I know
of no equivalent for the return path.

More importantly, what you are proposing is a code smell IMHO. Your
components should be sufficiently independent so as they do not
especially care when the user leaves the "app" and returns to the
"app". Or, leaving/returning isn't the right metric. For example, for
an app that is so secure that it needs it own password,
leaving/returning is immaterial -- it's whether the user credentials
are stale when an activity returns to the foreground that matters.

To draw an analogy, a Web app should not care when the user minimizes
their browser window.

With that in mind, what specifically are you trying to achieve? Why do
you think that you need to worry about when users leave the "app" and
return to the "app".

On Wed, Jan 18, 2012 at 5:05 PM, TonyD <tony@evertrue.com> wrote:
> Hi All,
>
> Is there a proper way to detect when someone leaves your application
> (hits the home button or opens a new application from the
> notifications bar ... basically the app leaves the foreground) or when
> someone enters your application (after hitting the home button).  I
> have multiple activities for this app so I cannot use any one activity
> lifecycle method because they happen when activities open and close
> inside the app and exiting/entering the app.  I also cannot use a
> custom application's onCreate method because coming back into the app
> after pressing the home button doesn't execute that function.
>
> I was thinking to either track all my activity's onPause, onResume,
> and onStop methods because the onResume of the next activity is called
> in between the onPause and onStop of the last activity (if i see all
> three happen in order within my application then I know that the user
> is still in my application) or every time the onPause or onStop method
> is called, check the foreground process and see if it's package name
> is my app.
>
> Is either one of these better than the other?  Is there a more common/
> standard way of doing this?
>
> Tony
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.7 Available!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate