Hi Mark,
Thanks for the quick reply. I am implementing a sort of authentication
where the user has to authenticate every time they reenter the app,
but not if they are already in the app browsing around to different
activities. You mention that each activity should be independent;
however, I have to ping a server to see if the the user's token is
still good before asking to auth, so if each activity is independent
then this ping would happen every time an activity opens within the
app causing a delay in usage. Also, we have a timeout on the auth to
make it stale after so long, but we also need it to immediately be
stale when the app exits as per our requirements for this app.
Tony
On Jan 18, 5:29 pm, Mark Murphy wrote:
> 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 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+unsubscr...@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/commonsguyhttp://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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en