Thank you Mark,

I do know that I can you onStop method as it is supposed to be called
when ever something else comes on to the screen (in this case the home
page). But my situation is a little more complicated than that.

I have an address field and an option for gps[if its switched on]. But
in the bottom portion of the screen I will be loading my results based
on the location. Now since I have loaded the results using the
onCreate, its doing so. So I changed it to do all those things in the
onStart method so that the Activity life cycle goes on smoothly.

Thanks for the suggestion because of which I went through my
Activity's lifecycle to see how everything is going on.

But since I started trying to log everything to see the activity life
cycle, what I observed is that onStop method is not actually being
called when I click on home button. Its being called as soon as i open
my app again, which is not how I wanted it to do. The locationUpdates
should stop the moment the user hits home button.

The other thing is that I expected my stack to be as it is and as soon
as I open my app after hitting on home button, the activity which I
was previously in will be opened. But it restarted the app itself.

This is what I observed in my app.
Say I have a main activity A and another Activity B.
I come to Activity B from Activity A.
Then I click on home button.
It closes the app but does not yet call onStop on B.
Now I open my app and it now calls onStop on Activity B.
It starts Activity A again.
Now only when I click on button for activity B, it calls onRestart
method on Activity B.

So am I doing something wrong or is it supposed to work in that way or
is it a bug?

On Feb 19, 2:52 pm, Mark Murphy <[email protected]> wrote:
> Achanta wrote:
> > I understand that trying to capture home button clicks is a hack, but
> > I need to atleast close my current activity when the user clicks on
> > home button.
>
> <snip>
>
> > I need to do it as I am listening for location updates and I want to
> > stop the updates and also need to trash any location that was
> > available to me previously.
>
> Then stop location updates in onStop(). This will get invoked:
>
> -- when the user presses HOME
> -- when the user pressed BACK (en route to onDestroy())
> -- when the user takes a phone call
> -- when the user responds to a notification that brings up an activity
> -- etc.
>
> The one thing you may want to do is handle configuration changes
> yourself, so you won't be called with onStop() when the user rotates the
> screen.
>
> > I need to do this just in case any user while in that activity clicks
> > on home button and changes the location settings.
>
> I'm not sure what "the location settings" are. If you mean they disable
> GPS, your LocationListener should be notified of that.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://twitter.com/commonsguy
>
> Android Training in US: 26-30 April 2010:http://onlc.com

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

Reply via email to