I recently wrote my first android app, and I too did not grasp the
life cycle functions and they just didn't seem to work correctly, or
the way I thought they should based on the graph. Here's my learned
knowledge from writing my app.

OnPause and onResume turned out to be by far and above the only
functions that are used and needed, at least for me. At first I was
trying to add in all the functions and never saw onStop or onStart
called, ever. So I press back or home, and onPause is the first to get
called, ALWAYS, no matter what for me. And going right back to my app,
OnResume is the one that gets called, ALWAYS, no matter what.

My app is simple so I had no need for saved state stuff, but I
experimented with it anyway putting it in my OnCreate and saved
instance state, just to see it work.

OnDestroy I never used, never seen it called, and I believe its only
needed if the OS closes it for more memory. And this condition
virtually never happens from my testing, so its almost not even needed
in a way.

I later added a service to my app, and that's where I then used
onStart and onStop. They didn't turn out to be used or needed in an
activity, only a service.

That's about it unless you want more details of my experience. Pause
and resume are the ones to use unless you have very complex conditions
happening in your app.

On Mar 12, 12:55 pm, DulcetTone <dulcett...@gmail.com> wrote:
> I find the flowchart of Activity lifecycle pretty ambiguous.  In a
> perfect world, it would receive a little more work to resolve the
> gray, but I'll throw out some example issues.
>
> 1.  The phrasing on the legs into and out of onPause() are vague.
> Does "another activity comes in front of the activity" pertain to the
> case where my activity is simply going away because finish() was
> called?  Does "the activity is no longer visible" mean that my
> activity is entirely concealed, and would this then differ from the
> case where another activity appeared partially in front of my own?
>
> 2.  what happens if you call finish() from within onCreate()?
> onStart()?  just about anywhere except the green "activity is running"
> blob?
>
> 3.  How is onPause() -> onResume() different than onStop() ->
> onRestart()?  What circumstances differentiate the flow?
>
> 4.  minor nits:  the clarity of the chart is actually diminished by
> having an exit from the "The process is killed" state, and some
> mention as to whether the Activity object may be re-used should follow
> the onDestroy() state
>
> The thing I am specifically trying to do is this:
>
> I want to perform certain actions when the BACK or HOME keys are
> pressed, and ignore cases where a third-party activity simply pops up
> on part of the screen and then goes away.  Not all phones are
> traversing the lifecycle graph the same way, it seems, and since I do
> not have one of every phone (Droids seem notoriously different),
> writing test cases is not a viable means of educating myself.  I'd
> like some clarity on the designed behavior that can be vouched for.
>
> tone

-- 
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

Reply via email to