Re: [android-developers] Re: How to close an activity when the user clicks on home button

2010-02-20 Thread Mark Murphy
Achanta wrote:
 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. 

:: blink, blink ::

 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.

I just tried it on an app I'm working on (Android 2.1), and onStop() was
called at the point I pressed the HOME button.

Are you doing anything unusual in your manifest vis a via
android:launchMode or similar settings?

 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.

I just tried it with this same scenario (Activity A - Activity B -
HOME), and again, onStop() was called at the point I pressed HOME.

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

Well, there appears to be something afoot either with your app or with
your environment. onStop(), at least as of Android 2.1, seems to behave
as documented for fairly ordinary stuff. Mind you that my test code does
not mess with android:launchMode or flags on activity starting or
whatever, so if you are, that's something to experiment with.

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

Android Development Wiki: http://wiki.andmob.org

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


[android-developers] Re: How to close an activity when the user clicks on home button

2010-02-20 Thread intbt
it may be as simple as adding

android:clearTaskOnLaunch=true

in your Manifest under the main activity tag to re-initialize after
returning to Home screen.

intbt



On Feb 20, 4:54 am, Mark Murphy mmur...@commonsware.com wrote:
 Achanta wrote:
  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.

 :: blink, blink ::

  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.

 I just tried it on an app I'm working on (Android 2.1), and onStop() was
 called at the point I pressed the HOME button.

 Are you doing anything unusual in your manifest vis a via
 android:launchMode or similar settings?

  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.

 I just tried it with this same scenario (Activity A - Activity B -
 HOME), and again, onStop() was called at the point I pressed HOME.

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

 Well, there appears to be something afoot either with your app or with
 your environment. onStop(), at least as of Android 2.1, seems to behave
 as documented for fairly ordinary stuff. Mind you that my test code does
 not mess with android:launchMode or flags on activity starting or
 whatever, so if you are, that's something to experiment with.

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

 Android Development Wiki:http://wiki.andmob.org

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


[android-developers] Re: How to close an activity when the user clicks on home button

2010-02-20 Thread Achanta

 I just tried it on an app I'm working on (Android 2.1), and onStop() was
 called at the point I pressed the HOME button.

I am using Android 1.6 as I need to support all the phones which are
working on that version also. And in this version or atleast for my
situation its not working so.


 Are you doing anything unusual in your manifest vis a via
 android:launchMode or similar settings?
Yes I was using launchMode=singleTask. I actually wanted
singleInstance but somehow Voice recognizer is giving a connection
problem when I use singleInstance.

So just to see if it is working in the way you suggested, I tried
removing all the launchMode etc in manifest and just left the activity
name and label. This time onStop method or the onRestart method are
never ever called.

But these are being called when I set finishTaskOnLaunch to true in
the manifest.

Thank you anyway for the help and the suggestions. I atleast got it to
work to the most extent if not stopping the updates and the activity
on clicking 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.

 I just tried it with this same scenario (Activity A - Activity B -
 HOME), and again, onStop() was called at the point I pressed HOME.

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

 Well, there appears to be something afoot either with your app or with
 your environment. onStop(), at least as of Android 2.1, seems to behave
 as documented for fairly ordinary stuff. Mind you that my test code does
 not mess with android:launchMode or flags on activity starting or
 whatever, so if you are, that's something to experiment with.

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

 Android Development Wiki:http://wiki.andmob.org

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


[android-developers] Re: How to close an activity when the user clicks on home button

2010-02-20 Thread Achanta
Thankyou,

I needed finishTaskonLaunch as that is more suitable than
clearTaskOnLaunch for my case as I need to close the activity itself
which I am opening in a separate task.

On Feb 20, 10:56 am, intbt in...@tacberry.com wrote:
 it may be as simple as adding

 android:clearTaskOnLaunch=true

 in your Manifest under the main activity tag to re-initialize after
 returning to Home screen.

 intbt

 On Feb 20, 4:54 am, Mark Murphy mmur...@commonsware.com wrote:

  Achanta wrote:
   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.

  :: blink, blink ::

   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.

  I just tried it on an app I'm working on (Android 2.1), and onStop() was
  called at the point I pressed the HOME button.

  Are you doing anything unusual in your manifest vis a via
  android:launchMode or similar settings?

   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.

  I just tried it with this same scenario (Activity A - Activity B -
  HOME), and again, onStop() was called at the point I pressed HOME.

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

  Well, there appears to be something afoot either with your app or with
  your environment. onStop(), at least as of Android 2.1, seems to behave
  as documented for fairly ordinary stuff. Mind you that my test code does
  not mess with android:launchMode or flags on activity starting or
  whatever, so if you are, that's something to experiment with.

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

  Android Development Wiki:http://wiki.andmob.org



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


[android-developers] Re: How to close an activity when the user clicks on home button

2010-02-19 Thread Achanta
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 mmur...@commonsware.com 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 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