[android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-12 Thread Achanta
So I have modified my thread to be a singleton and mimplemented it
like this. Hope it helps someone else who might be facing the same
issue.

public class SingletonThread extends Thread{
private static SingletonThread _instance;
public static boolean IS_RUNNING = false;
private static Context mContext;

private SingletonThread(){
}

public synchronized static final SingletonThread getInstance(Context
context){
mContext = context;
if(instance == null){
instance = new SingletonThread();
}
return instance;
}

public synchronized void run(){
IS_RUNNING = true;
//Implement your requirements.
IS_RUNNING = false;
}
}

And whenever I call the getInstance, from any other UI thread, I will
check for IS_RUNNING also and will start the thread only if IS_RUNNING
is false/will wait till IS_RUNNING is false.

There might be better ways to do this, so please post your feedbacks,

Thank you.


On Mar 11, 2:44 pm, Dianne Hackborn hack...@android.com wrote:
 On Thu, Mar 11, 2010 at 1:40 PM, Achanta krishna.acha...@gmail.com wrote:
  Yes I am trying to redesign it to use AsyncTask. One reason why I did
  not take this approach is that I just wanted a plain thread that sits
  and logs user events that are occurring throughout my app and it made
  more sense to just start that thread when the app starts and shut it
  down when the app closes. I had a handler which grabs the logs and
  puts them in db and the thread just sits there and logs them to
  server.

 For this model, manage the thread through a separate static singleton, have
 clients tell it when they are using it (in onCreate() or whatever) and when
 they are done (in onDestroy() or whatever), and have that class take care of
 stopping the thread when there are no more clients.

 Also please be careful about what this thread is doing.  An application
 should be careful to be doing very little work any time it is not in the
 foreground, or it will be consuming battery...  and has a good chance of
 showing up high up in the battery meter as it eats the user's battery.

 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 Note: please don't send private questions to me, as I don't have time to
 provide private support, and so won't reply to such e-mails.  All such
 questions should be posted on public forums, where I and others can see and
 answer them.

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread Achanta
Thank you Dianne,

Its not even passing onStop and onDestroy at some point in the future.
It is only doing it in some point in the future when more activities
are started. I tested it 4-5 times and let it run for atleast 5
minutes. So I don't know how long I have to wait for the thread to
close.

Can anyone suggest a work around for this issue.
I have a background thread which starts in the onCreate methos and
which I close in the onDestroy method. But because of this bug in the
sdk 2.1 my thread never stops. But when the user closes the
app[onDestroy hasn't been called] and opens my application again, I
try to create the thread in the onCreate. But after this is done at
some point the onDestroy from the earlier activity is called which
sends a messahe to my thread's handler to stop the thread. So the app
runs now but the background thread doesnot run.

Another problem that I face with the same issue is since the handle
passes the message to stop the thread even while it is supposed to
run, my events trigger actions where i have to write to database from
the background thread. Now since that is null it shows the force close
message.

The only option that I see is to detect the build version each time my
app starts and try to limit the things the user can do in those
versions, which ofcourse is not much more than just undesirable
thing.

Please let me know if anyone has a workaround for this one.

thank you.

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


Re: [android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread Mark Murphy
Achanta wrote:
 Can anyone suggest a work around for this issue.
 I have a background thread which starts in the onCreate methos and
 which I close in the onDestroy method. But because of this bug in the
 sdk 2.1 my thread never stops. But when the user closes the
 app[onDestroy hasn't been called] and opens my application again, I
 try to create the thread in the onCreate. But after this is done at
 some point the onDestroy from the earlier activity is called which
 sends a messahe to my thread's handler to stop the thread. So the app
 runs now but the background thread doesnot run.

You may be able to redesign your application to not require a permanent
background thread. For example, use discrete AsyncTasks that do some
work and end.

 Another problem that I face with the same issue is since the handle
 passes the message to stop the thread even while it is supposed to
 run, my events trigger actions where i have to write to database from
 the background thread. Now since that is null it shows the force close
 message.

I have no idea what this means.

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

Android Training in US: 14-18 June 2010: http://bignerdranch.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


[android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread Achanta
Thank you Mark,

Yes I am trying to redesign it to use AsyncTask. One reason why I did
not take this approach is that I just wanted a plain thread that sits
and logs user events that are occurring throughout my app and it made
more sense to just start that thread when the app starts and shut it
down when the app closes. I had a handler which grabs the logs and
puts them in db and the thread just sits there and logs them to
server.

I saw the google tracker but the apis for analytics are not yet good
enough to provide us all the data which we can integrate into our
marketing tools.

I still hope this issue will be resolved soon.

On Mar 11, 2:26 pm, Mark Murphy mmur...@commonsware.com wrote:
 Achanta wrote:
  Can anyone suggest a work around for this issue.
  I have a background thread which starts in the onCreate methos and
  which I close in the onDestroy method. But because of this bug in the
  sdk 2.1 my thread never stops. But when the user closes the
  app[onDestroy hasn't been called] and opens my application again, I
  try to create the thread in the onCreate. But after this is done at
  some point the onDestroy from the earlier activity is called which
  sends a messahe to my thread's handler to stop the thread. So the app
  runs now but the background thread doesnot run.

 You may be able to redesign your application to not require a permanent
 background thread. For example, use discrete AsyncTasks that do some
 work and end.

  Another problem that I face with the same issue is since the handle
  passes the message to stop the thread even while it is supposed to
  run, my events trigger actions where i have to write to database from
  the background thread. Now since that is null it shows the force close
  message.

 I have no idea what this means.

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

 Android Training in US: 14-18 June 2010:http://bignerdranch.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


Re: [android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread Dianne Hackborn
On Thu, Mar 11, 2010 at 1:13 PM, Achanta krishna.acha...@gmail.com wrote:

 Its not even passing onStop and onDestroy at some point in the future.
 It is only doing it in some point in the future when more activities
 are started. I tested it 4-5 times and let it run for atleast 5
 minutes. So I don't know how long I have to wait for the thread to
 close.


What I was trying to say is that it will not completely forget to destroy it
-- onDestroy() WILL be called, just at some time later.  Possibly a lot
later if the user sits in home for a long time.


 Can anyone suggest a work around for this issue.
 I have a background thread which starts in the onCreate methos and
 which I close in the onDestroy method. But because of this bug in the
 sdk 2.1 my thread never stops. But when the user closes the
 app[onDestroy hasn't been called] and opens my application again, I
 try to create the thread in the onCreate. But after this is done at
 some point the onDestroy from the earlier activity is called which
 sends a messahe to my thread's handler to stop the thread. So the app
 runs now but the background thread doesnot run.


This is actually a bug in the app -- there is no guarantee that onDestroy()
will be called before a new instance is created.  For example, if you press
back to exiting the activity and then very quickly start a new instance, the
new instance will be started before onDestroy() because we wait until the
apps are idle until destroying activities.  The bug here just makes this
case a lot more likely to happen.  You should keep the state from two
instances of an activity distinct -- for example if your onDestroy() is
called it should only impact state in the activity being destroyed.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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

Re: [android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread Dianne Hackborn
On Thu, Mar 11, 2010 at 1:40 PM, Achanta krishna.acha...@gmail.com wrote:

 Yes I am trying to redesign it to use AsyncTask. One reason why I did
 not take this approach is that I just wanted a plain thread that sits
 and logs user events that are occurring throughout my app and it made
 more sense to just start that thread when the app starts and shut it
 down when the app closes. I had a handler which grabs the logs and
 puts them in db and the thread just sits there and logs them to
 server.


For this model, manage the thread through a separate static singleton, have
clients tell it when they are using it (in onCreate() or whatever) and when
they are done (in onDestroy() or whatever), and have that class take care of
stopping the thread when there are no more clients.

Also please be careful about what this thread is doing.  An application
should be careful to be doing very little work any time it is not in the
foreground, or it will be consuming battery...  and has a good chance of
showing up high up in the battery meter as it eats the user's battery.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread Achanta
Hey Dianne,

Thank you for the tip on battery life. Will definitely try to make it
as good as possible for the battery life.

Yes I considered using singleton pattern but again I still face with
the issue where onDestroy will be called after onCreate when it should
not happen and I need to keep track of that case also. So I would just
go with AsynkTask but take care that my app is not eating up the
battery.

Thank you.

On Mar 11, 2:44 pm, Dianne Hackborn hack...@android.com wrote:
 On Thu, Mar 11, 2010 at 1:40 PM, Achanta krishna.acha...@gmail.com wrote:
  Yes I am trying to redesign it to use AsyncTask. One reason why I did
  not take this approach is that I just wanted a plain thread that sits
  and logs user events that are occurring throughout my app and it made
  more sense to just start that thread when the app starts and shut it
  down when the app closes. I had a handler which grabs the logs and
  puts them in db and the thread just sits there and logs them to
  server.

 For this model, manage the thread through a separate static singleton, have
 clients tell it when they are using it (in onCreate() or whatever) and when
 they are done (in onDestroy() or whatever), and have that class take care of
 stopping the thread when there are no more clients.

 Also please be careful about what this thread is doing.  An application
 should be careful to be doing very little work any time it is not in the
 foreground, or it will be consuming battery...  and has a good chance of
 showing up high up in the battery meter as it eats the user's battery.

 --
 Dianne Hackborn
 Android framework engineer
 hack...@android.com

 Note: please don't send private questions to me, as I don't have time to
 provide private support, and so won't reply to such e-mails.  All such
 questions should be posted on public forums, where I and others can see and
 answer them.

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


Re: [android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread Dianne Hackborn
On Thu, Mar 11, 2010 at 1:59 PM, Achanta krishna.acha...@gmail.com wrote:

 Yes I considered using singleton pattern but again I still face with
 the issue where onDestroy will be called after onCreate when it should
 not happen and I need to keep track of that case also. So I would just
 go with AsynkTask but take care that my app is not eating up the
 battery.


As I said, it is not true that this should not happen.  In fact it can and
will happen.  The system bug here just makes it (a lot) more likely to
happen.

And for anyone wondering, the singleTask or singleInstance launch modes do
not impact this, that is not what they are for.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread skyhigh
This issue has been causing serious problems for users of my audiobook
player application on 2.1 phones.  The problems with the activity life
cycle cause corresponding problems with the service life cycle.

A service allows onStart to be called multiple times for the same
service instance.  This is normal expected behavior for a service.
But when the start and stop intents being given to the service get
reordered it causes serious problems.  This is because the sequence:

Service.onCreate
Service.onStart
Service.onStart
Service.onDestroy

is a valid sequence to execute on a service, and even though onStart
is called multiple times it is correct behavior that the service to be
destroyed on the first stop service command.

Take the simple case where an activity starts a service in onCreate
and stops the service in onDestroy.  Bringing up the activity two
times should result in the following sequence:

1st use
Activity.onCreate (starts service)
Service.onCreate
Service.onStart
Activity.finish
Activity.onDestroy (stops service)
Service.onDestroy

2nd use
Activity.onCreate (starts service)
Service.onCreate
Service.onStart
Activity.finish
Activity.onDestroy (stops service)
Service.onDestroy

Because of this activity life cycle bug the following is occurring on
2.1 phones:

1st use
Activity.onCreate (starts service)
Service.onCreate
Service.onStart
Activity.finish (the destroy gets delayed)

2nd use
Activity.onCreate (starts service)
Service.onStart (service still exists)

delayed
Activity.onDestroy (stops service)
Service.onDestroy

At this point the 2nd activity instance is running but the service is
it using has now been destroyed.  The point at which the service gets
destroyed randomly occurs when the delayed Activity.onDestroy was
called.

The way I plan to work around this issue is to change my activity to
send the stop service intent just prior to calling Activity.finish.
This way the stop service intent will be executed at the correct point
in time even if the activity onStop and onDestroy get delayed until
later.

This problem has been difficult to track down not having a 2.1 device
myself.  I should have validation from some of my customers soon as to
whether this work around resolves the problems they have been having.

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


Re: [android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-11 Thread Dianne Hackborn
Note again that though this bug makes this issue happen much more
frequently, it CAN happen in normal situations.  I am sorry for the trouble
this has caused, however as a rule it is correct to design your code without
the assumption that onDestroy() will happen before onCreate().

On Thu, Mar 11, 2010 at 8:15 PM, skyhigh skyhigh1...@gmail.com wrote:

 This issue has been causing serious problems for users of my audiobook
 player application on 2.1 phones.  The problems with the activity life
 cycle cause corresponding problems with the service life cycle.

 A service allows onStart to be called multiple times for the same
 service instance.  This is normal expected behavior for a service.
 But when the start and stop intents being given to the service get
 reordered it causes serious problems.  This is because the sequence:

 Service.onCreate
 Service.onStart
 Service.onStart
 Service.onDestroy

 is a valid sequence to execute on a service, and even though onStart
 is called multiple times it is correct behavior that the service to be
 destroyed on the first stop service command.

 Take the simple case where an activity starts a service in onCreate
 and stops the service in onDestroy.  Bringing up the activity two
 times should result in the following sequence:

 1st use
 Activity.onCreate (starts service)
 Service.onCreate
 Service.onStart
 Activity.finish
 Activity.onDestroy (stops service)
 Service.onDestroy

 2nd use
 Activity.onCreate (starts service)
 Service.onCreate
 Service.onStart
 Activity.finish
 Activity.onDestroy (stops service)
 Service.onDestroy

 Because of this activity life cycle bug the following is occurring on
 2.1 phones:

 1st use
 Activity.onCreate (starts service)
 Service.onCreate
 Service.onStart
 Activity.finish (the destroy gets delayed)

 2nd use
 Activity.onCreate (starts service)
 Service.onStart (service still exists)

 delayed
 Activity.onDestroy (stops service)
 Service.onDestroy

 At this point the 2nd activity instance is running but the service is
 it using has now been destroyed.  The point at which the service gets
 destroyed randomly occurs when the delayed Activity.onDestroy was
 called.

 The way I plan to work around this issue is to change my activity to
 send the stop service intent just prior to calling Activity.finish.
 This way the stop service intent will be executed at the correct point
 in time even if the activity onStop and onDestroy get delayed until
 later.

 This problem has been difficult to track down not having a 2.1 device
 myself.  I should have validation from some of my customers soon as to
 whether this work around resolves the problems they have been having.

 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-10 Thread Alex
I'm having a similar lifecycle issue on the Nexus One.

Start the app -OnCreate
Hit back - no OnDestroy is called
Run app again -OnCreate, followed by OnDestroy

The wierd thing is that it doesn't actually kill our application, so
it is left in a broken state since we are tearing things down in
OnDestroy.

-Alex

On Mar 7, 11:27 am, skyhigh skyhigh1...@gmail.com wrote:
 Very few of my activities used onStart and onStop until recently when
 I instrumented my application with Flurry Analytics.  If you follow
 the Flurry instrumentation instructions then you add calls to notify
 Flurry about your application activity in the onStart and onStop
 methods for everyoneof your activities.  I am not sure what impact
 it will have on the Flurry statistics gathering if these routines
 don't get called.

 I have had users reporting problems with my application on 2.1 phones
 which may be related to the service life cycle not behaving properly
 on these phones.  I don't currently have a 2.1 phone to test this on
 (I am waiting to get my device seeding phone).  I built an
 instrumented beta build that will log the service life cycle
 information for me, and am waiting for a customer to run the
 instrumented beta build on their 2.1 phone and send me back the
 logcat, so I can see if there is a similar issue with services.

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-10 Thread Achanta
I too have the same issue and Mark, we discussed it earlier in another
thread. I was trying to use the onStop and onDestroy to stop Location
updates and other background threads that I start from onCreate
method.

Here is what I observed.

Here is what I have seen. I am using Nexus one [2.1].
Pressing on Home button or the Back button from my main activity does
not call the onStop method or onDestroy method in this case
Activities A, B.
Activity A has a Button which starts activity B.

Now when the activity A is started normally and it does not start
another thread then the Back button from Activity A is called onStop
and onDestroy.
But if the Activity B is started from Activity A or if there is
another thread that has been started from Activity A and if we come
back to Activity A from Activity B and then press on the Back button,
then onStop and onDestroy are not immediately called. But they are
called after some other activity/application are opened.
I even observed that they are not always immediately called after
opening the same activity A. Sometimes they are called after activity
A starts Activity B.

1. start A
 Press Back.
 onStop and onDwstroy called.

2. start A.
   Start another thread or activity from A and come back to A.
   Click on Back Button From A.
   onStop and onDestroy are not called.
   Start another application or the same application.
   onStop and onDestroy are sometimes[not always immediately] called.
   start opening more activities.
   onStop and onDestroy will be called at some point.

3. Start Activity A.
   Click on Home button.
   onStop is never called. [or atleast on two nexus one phones that I
tested atleast a few times].
 it will be called at a later point when another application or the
same application is opened. And just like onStop, this is not in any
predicted manner but is called at some point.


On Mar 10, 10:07 am, Alex acni...@gmail.com wrote:
 I'm having a similar lifecycle issue on the Nexus One.

 Start the app -OnCreate
 Hitback- no OnDestroy is called
 Run app again -OnCreate, followed by OnDestroy

 The wierd thing is that it doesn't actually kill our application, so
 it is left in a broken state since we are tearing things down in
 OnDestroy.

 -Alex

 On Mar 7, 11:27 am, skyhigh skyhigh1...@gmail.com wrote:

  Very few of my activities used onStart and onStop until recently when
  I instrumented my application with Flurry Analytics.  If you follow
  the Flurry instrumentation instructions then you add calls to notify
  Flurry about your application activity in the onStart and onStop
  methods for everyoneof your activities.  I am not sure what impact
  it will have on the Flurry statistics gathering if these routines
  don't get called.

  I have had users reporting problems with my application on 2.1 phones
  which may be related to the service life cycle not behaving properly
  on these phones.  I don't currently have a 2.1 phone to test this on
  (I am waiting to get my device seeding phone).  I built an
  instrumented beta build that will log the service life cycle
  information for me, and am waiting for a customer to run the
  instrumented beta build on their 2.1 phone and send mebackthe
  logcat, so I can see if there is a similar issue with services.



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


Re: [android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-10 Thread Dianne Hackborn
Hi, there is an issue in 2.1 with the new launcher that causes the
onStop()/onDestroy() to be delayed longer than typical when going back to
home.  Note these are not delayed -forever-, but just until later in the
future (when the next activity switch happens).  These methods are defined
to happen at some time in the future so technically it is not really
broken, but this is certainly not the desired behavior here.  This will be
fixed in the next release.

Fwiw, this happened because the new launcher has a special surface view on
top of itself to display the 3d all apps, and this caused the window manager
to be confused and not realize that the app behind it had been hidden so it
could then be stopped/destroyed.

On Wed, Mar 10, 2010 at 6:33 PM, Achanta krishna.acha...@gmail.com wrote:

 I too have the same issue and Mark, we discussed it earlier in another
 thread. I was trying to use the onStop and onDestroy to stop Location
 updates and other background threads that I start from onCreate
 method.

 Here is what I observed.

 Here is what I have seen. I am using Nexus one [2.1].
 Pressing on Home button or the Back button from my main activity does
 not call the onStop method or onDestroy method in this case
 Activities A, B.
 Activity A has a Button which starts activity B.

 Now when the activity A is started normally and it does not start
 another thread then the Back button from Activity A is called onStop
 and onDestroy.
 But if the Activity B is started from Activity A or if there is
 another thread that has been started from Activity A and if we come
 back to Activity A from Activity B and then press on the Back button,
 then onStop and onDestroy are not immediately called. But they are
 called after some other activity/application are opened.
 I even observed that they are not always immediately called after
 opening the same activity A. Sometimes they are called after activity
 A starts Activity B.

 1. start A
  Press Back.
  onStop and onDwstroy called.

 2. start A.
   Start another thread or activity from A and come back to A.
   Click on Back Button From A.
   onStop and onDestroy are not called.
   Start another application or the same application.
   onStop and onDestroy are sometimes[not always immediately] called.
   start opening more activities.
   onStop and onDestroy will be called at some point.

 3. Start Activity A.
   Click on Home button.
   onStop is never called. [or atleast on two nexus one phones that I
 tested atleast a few times].
  it will be called at a later point when another application or the
 same application is opened. And just like onStop, this is not in any
 predicted manner but is called at some point.


 On Mar 10, 10:07 am, Alex acni...@gmail.com wrote:
  I'm having a similar lifecycle issue on the Nexus One.
 
  Start the app -OnCreate
  Hitback- no OnDestroy is called
  Run app again -OnCreate, followed by OnDestroy
 
  The wierd thing is that it doesn't actually kill our application, so
  it is left in a broken state since we are tearing things down in
  OnDestroy.
 
  -Alex
 
  On Mar 7, 11:27 am, skyhigh skyhigh1...@gmail.com wrote:
 
   Very few of my activities used onStart and onStop until recently when
   I instrumented my application with Flurry Analytics.  If you follow
   the Flurry instrumentation instructions then you add calls to notify
   Flurry about your application activity in the onStart and onStop
   methods for everyoneof your activities.  I am not sure what impact
   it will have on the Flurry statistics gathering if these routines
   don't get called.
 
   I have had users reporting problems with my application on 2.1 phones
   which may be related to the service life cycle not behaving properly
   on these phones.  I don't currently have a 2.1 phone to test this on
   (I am waiting to get my device seeding phone).  I built an
   instrumented beta build that will log the service life cycle
   information for me, and am waiting for a customer to run the
   instrumented beta build on their 2.1 phone and send mebackthe
   logcat, so I can see if there is a similar issue with services.
 
 

 --
 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.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email 

[android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-07 Thread skyhigh
Very few of my activities used onStart and onStop until recently when
I instrumented my application with Flurry Analytics.  If you follow
the Flurry instrumentation instructions then you add calls to notify
Flurry about your application activity in the onStart and onStop
methods for every one of your activities.  I am not sure what impact
it will have on the Flurry statistics gathering if these routines
don't get called.

I have had users reporting problems with my application on 2.1 phones
which may be related to the service life cycle not behaving properly
on these phones.  I don't currently have a 2.1 phone to test this on
(I am waiting to get my device seeding phone).  I built an
instrumented beta build that will log the service life cycle
information for me, and am waiting for a customer to run the
instrumented beta build on their 2.1 phone and send me back the
logcat, so I can see if there is a similar issue with services.


-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-05 Thread Zuli
I agree with Mark Murphy, it seems a problem only when the home screen
is displayed after the activity, if I open another activity on top of
that (long press on HOME) or if I receive a call the onStop is
correctly called...
seems to me quite a big issue, think about all the activities that use
the onstart and onstop methods to coordinate their work, how come so
few people have noticed that?

Zuli


On Mar 5, 6:00 am, Streets Of Boston flyingdutc...@gmail.com wrote:
 mm... my app makes use of saving and restoring instance state a
 lot and it works as well on theNexusOneas on the Droid or G1. But i
 don't use the onStop callback at all. And I don't use the
 onRestoreInstanceState either. Instead, i use the
 onRetainNonConfigurationInstance() and
 getLastNonConfigurationInstance() methods. These work well for me.

 On Mar 4, 8:25 pm, Zsolt Vasvari zvasv...@gmail.com wrote:



  I think there are some issues with the background activity life cycle
  management on theNexusOne.

  In my app, I have a background and foreground activity.  When I tilt
  the phone so it switches orientation, the first time around the state
  is properly saved and restored for the background acrivity.  But if
  when flip it back, onCreate is called with NULL for the Bundle, so I
  lose state. (and no, onRestoreInstanceState is not called, either)

  I'd create a small app that demonstrates this, but frankly, it would
  be a waste of my time as it probably wouldn't get looked at anyhow.
  So just take my word for it

  Zsolt Vasvari

  On Mar 5, 4:29 am, Mark Murphy mmur...@commonsware.com wrote:

   Mark Murphy wrote:
schwiz wrote:
It should be called when you press back but not home, but I have
noticed this problem using openeclair on my G1.  Perhaps its a new
feature/bug in 2.1?

No, onStop() should be called when you press either BACK or HOME. For
some reason, it is not doing that in theNexusOne. My best guess is
that it has to do with theNexusOne'shome screen implementation, but
that's just a guess.

   BTW, here's the open issue:

  http://code.google.com/p/android/issues/detail?id=6094

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

   _Android Programming Tutorials_ Version 2.0 Available!- Hide quoted text -

  - Show quoted text -

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-05 Thread Streets Of Boston
I think a lot of apps don't use the onStop or onStart.
I never found a use for them (so far...).

onCreate, onResume, onPause and onDestroy are the most important ones.
The NonConfigurationInstance() methods for configuration changes.


On Mar 5, 9:26 am, Zuli paolo.zuli...@gmail.com wrote:
 I agree with Mark Murphy, it seems a problem only when the home screen
 is displayed after the activity, if I open another activity on top of
 that (long press on HOME) or if I receive a call the onStop is
 correctly called...
 seems to me quite a big issue, think about all the activities that use
 the onstart and onstop methods to coordinate their work, how come so
 few people have noticed that?

 Zuli

 On Mar 5, 6:00 am, Streets Of Boston flyingdutc...@gmail.com wrote:



  mm... my app makes use of saving and restoring instance state a
  lot and it works as well on theNexusOneas on the Droid or G1. But i
  don't use the onStop callback at all. And I don't use the
  onRestoreInstanceState either. Instead, i use the
  onRetainNonConfigurationInstance() and
  getLastNonConfigurationInstance() methods. These work well for me.

  On Mar 4, 8:25 pm, Zsolt Vasvari zvasv...@gmail.com wrote:

   I think there are some issues with the background activity life cycle
   management on theNexusOne.

   In my app, I have a background and foreground activity.  When I tilt
   the phone so it switches orientation, the first time around the state
   is properly saved and restored for the background acrivity.  But if
   when flip it back, onCreate is called with NULL for the Bundle, so I
   lose state. (and no, onRestoreInstanceState is not called, either)

   I'd create a small app that demonstrates this, but frankly, it would
   be a waste of my time as it probably wouldn't get looked at anyhow.
   So just take my word for it

   Zsolt Vasvari

   On Mar 5, 4:29 am, Mark Murphy mmur...@commonsware.com wrote:

Mark Murphy wrote:
 schwiz wrote:
 It should be called when you press back but not home, but I have
 noticed this problem using openeclair on my G1.  Perhaps its a new
 feature/bug in 2.1?

 No, onStop() should be called when you press either BACK or HOME. For
 some reason, it is not doing that in theNexusOne. My best guess is
 that it has to do with theNexusOne'shome screen implementation, but
 that's just a guess.

BTW, here's the open issue:

   http://code.google.com/p/android/issues/detail?id=6094

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

_Android Programming Tutorials_ Version 2.0 Available!- Hide quoted 
text -

   - Show quoted text -- Hide quoted text -

 - Show quoted text -

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-04 Thread Matias Alberto de la Vega
Zuli, onStop() is called when your Activity is no longer visible, this
may happen if a new activity is created (full screen mode) and is
positioned in front of yours, also it may be caused because another
Activity is resumed and brought to front (also full screen) and in the
last case onStop() is called when your Activity is about to be
destroyed (prior to onDestroy). After onPause() is called there are
two options, onRestart() is called to restart your Activity or
onDestroy() is called to kill your activity. Hope this helped. Bye

On 4 mar, 13:26, Zuli paolo.zuli...@gmail.com wrote:
 Hi,
 I have a problem with the activity lifecycle specifically on Nexus One
 (2.1 running on emulator works fine).
 If I just create a simple empty Activity with no special launchModes
 that logs the calls on the onStart and onStop methods, this is what I
 see:

 - launch app: onStart called;
 - home button: onStop NOT called;
 - launch app: onStart NOT called;
 - home button: onStop NOT called:

 and so on. Sometimes if I press the back button then the onStop is not
 called, but the when i launch the activity again the onStart is called
 and right after the onStop is called.
 Similar results with different launchModes...

 What is going on? Can anyone confirm this?

 Zuli

 i found an android issue for the problem 
 here:http://code.google.com/p/android/issues/detail?id=6094
 and a similar thread 
 herehttp://groups.google.com/group/android-developers/browse_thread/threa...

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-04 Thread Zuli
Hi Matias,
thanks for your reply, but that's not the point. Because onStop() is
called when the activity is no longer visibile, it should be called
when the user presses the HOME or BACK button, and that is not
happening on the Nexus One... well not on mine at least :)

Zuli


On Mar 4, 8:23 pm, Matias Alberto de la Vega
delavega.mat...@gmail.com wrote:
 Zuli, onStop() is called when your Activity is no longer visible, this
 may happen if a new activity is created (full screen mode) and is
 positioned in front of yours, also it may be caused because another
 Activity is resumed and brought to front (also full screen) and in the
 last case onStop() is called when your Activity is about to be
 destroyed (prior to onDestroy). After onPause() is called there are
 two options, onRestart() is called to restart your Activity or
 onDestroy() is called to kill your activity. Hope this helped. Bye

 On 4 mar, 13:26, Zuli paolo.zuli...@gmail.com wrote:



  Hi,
  I have a problem with the activity lifecycle specifically on Nexus One
  (2.1 running on emulator works fine).
  If I just create a simple empty Activity with no special launchModes
  that logs the calls on the onStart and onStop methods, this is what I
  see:

  - launch app: onStart called;
  - home button: onStop NOT called;
  - launch app: onStart NOT called;
  - home button: onStop NOT called:

  and so on. Sometimes if I press the back button then the onStop is not
  called, but the when i launch the activity again the onStart is called
  and right after the onStop is called.
  Similar results with different launchModes...

  What is going on? Can anyone confirm this?

  Zuli

  i found an android issue for the problem 
  here:http://code.google.com/p/android/issues/detail?id=6094
  and a similar thread 
  herehttp://groups.google.com/group/android-developers/browse_thread/threa...

-- 
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: Activity lifecycle problem on Nexus One - onStop not called

2010-03-04 Thread schwiz
It should be called when you press back but not home, but I have
noticed this problem using openeclair on my G1.  Perhaps its a new
feature/bug in 2.1?

On Mar 4, 1:54 pm, Zuli paolo.zuli...@gmail.com wrote:
 Hi Matias,
 thanks for your reply, but that's not the point. Because onStop() is
 called when the activity is no longer visibile, it should be called
 when the user presses the HOME or BACK button, and that is not
 happening on the Nexus One... well not on mine at least :)

 Zuli

 On Mar 4, 8:23 pm, Matias Alberto de la Vega

 delavega.mat...@gmail.com wrote:
  Zuli, onStop() is called when your Activity is no longer visible, this
  may happen if a new activity is created (full screen mode) and is
  positioned in front of yours, also it may be caused because another
  Activity is resumed and brought to front (also full screen) and in the
  last case onStop() is called when your Activity is about to be
  destroyed (prior to onDestroy). After onPause() is called there are
  two options, onRestart() is called to restart your Activity or
  onDestroy() is called to kill your activity. Hope this helped. Bye

  On 4 mar, 13:26, Zuli paolo.zuli...@gmail.com wrote:

   Hi,
   I have a problem with the activity lifecycle specifically on Nexus One
   (2.1 running on emulator works fine).
   If I just create a simple empty Activity with no special launchModes
   that logs the calls on the onStart and onStop methods, this is what I
   see:

   - launch app: onStart called;
   - home button: onStop NOT called;
   - launch app: onStart NOT called;
   - home button: onStop NOT called:

   and so on. Sometimes if I press the back button then the onStop is not
   called, but the when i launch the activity again the onStart is called
   and right after the onStop is called.
   Similar results with different launchModes...

   What is going on? Can anyone confirm this?

   Zuli

   i found an android issue for the problem 
   here:http://code.google.com/p/android/issues/detail?id=6094
   and a similar thread 
   herehttp://groups.google.com/group/android-developers/browse_thread/threa...

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


Re: [android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-04 Thread Mark Murphy
schwiz wrote:
 It should be called when you press back but not home, but I have
 noticed this problem using openeclair on my G1.  Perhaps its a new
 feature/bug in 2.1?

No, onStop() should be called when you press either BACK or HOME. For
some reason, it is not doing that in the Nexus One. My best guess is
that it has to do with the Nexus One's home screen implementation, but
that's just a guess.

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

_Android Programming Tutorials_ Version 2.0 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


Re: [android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-04 Thread Mark Murphy
Mark Murphy wrote:
 schwiz wrote:
 It should be called when you press back but not home, but I have
 noticed this problem using openeclair on my G1.  Perhaps its a new
 feature/bug in 2.1?
 
 No, onStop() should be called when you press either BACK or HOME. For
 some reason, it is not doing that in the Nexus One. My best guess is
 that it has to do with the Nexus One's home screen implementation, but
 that's just a guess.
 

BTW, here's the open issue:

http://code.google.com/p/android/issues/detail?id=6094

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

_Android Programming Tutorials_ Version 2.0 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


[android-developers] Re: Activity lifecycle problem on Nexus One - onStop not called

2010-03-04 Thread Streets Of Boston
mm... my app makes use of saving and restoring instance state a
lot and it works as well on the Nexus One as on the Droid or G1. But i
don't use the onStop callback at all. And I don't use the
onRestoreInstanceState either. Instead, i use the
onRetainNonConfigurationInstance() and
getLastNonConfigurationInstance() methods. These work well for me.

On Mar 4, 8:25 pm, Zsolt Vasvari zvasv...@gmail.com wrote:
 I think there are some issues with the background activity life cycle
 management on the Nexus One.

 In my app, I have a background and foreground activity.  When I tilt
 the phone so it switches orientation, the first time around the state
 is properly saved and restored for the background acrivity.  But if
 when flip it back, onCreate is called with NULL for the Bundle, so I
 lose state. (and no, onRestoreInstanceState is not called, either)

 I'd create a small app that demonstrates this, but frankly, it would
 be a waste of my time as it probably wouldn't get looked at anyhow.
 So just take my word for it

 Zsolt Vasvari

 On Mar 5, 4:29 am, Mark Murphy mmur...@commonsware.com wrote:



  Mark Murphy wrote:
   schwiz wrote:
   It should be called when you press back but not home, but I have
   noticed this problem using openeclair on my G1.  Perhaps its a new
   feature/bug in 2.1?

   No, onStop() should be called when you press either BACK or HOME. For
   some reason, it is not doing that in the Nexus One. My best guess is
   that it has to do with the Nexus One's home screen implementation, but
   that's just a guess.

  BTW, here's the open issue:

 http://code.google.com/p/android/issues/detail?id=6094

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

  _Android Programming Tutorials_ Version 2.0 Available!- Hide quoted text -

 - Show quoted text -

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