[android-beginners] Re: preventing Activity from destroying
There are other ways to make a Service always work even if the phone sleeps; it depends on what your Service does. For example, if the Service's job is to respond to an Activity, then it is awake when the Activity is awake. Or if it responds to a broadcast Intent, ditto. Generally speaking, a Service that keeps the phone awake all the time to run like a daemon will eat up the battery, but there are cases where that's necessary. Why does your Service need to stay awake? Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 10, 10:15 pm, Jason shivi...@gmail.com wrote: John Yes, you are right. Pressing Home does call just onStop; while pressing Back calls onDestroy. Btw, how do you ensure that the service keeps running and doing its job even when the phone goes to sleep (power save mode)? I added PowerManager = pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MyService); wl.acquire(); but it didn't seem to help On Wed, Sep 9, 2009 at 8:26 PM, John P. johnny.d.p...@gmail.com wrote: It is true that when the Back button is pressed, onDestroy() is called. But hitting the Home button invokes the activity's onStop() for me. Now, it is true that if Android determines it needs memory, it may then invoke onDestroy() on the stopped activity. It sounds like if you want your activity to do something while minimized (i.e. in the background with no user interaction), then this logic should really be in your service. I wrote a program where a service continuously does some processing while keeping its state. I have an activity that binds to the service, gets the state, and appropriately rehydrates its own state accordingly. Everytime the activity pauses, it unbinds. Everytime it resumes, it rebinds. All the continuous processing is done on the service, and the activity gives the user a chance to modify the data. But when the activity is dead, the service continues on until I explicitly kill it through the said activity. On Sep 9, 10:01 pm, Jason shivi...@gmail.com wrote: How do I achieve the effect of 'minimizing' a UI activity? I have a UI activity that gets destroyed each time I click the Home, phone etc. keys on the phone. I would like the UI activity to be sent to the background; since it is bound to a service and processing the data returned by the service continuously. Clicking on the app ends up calling onCreate, onStart again. I would like to restart (onResume) instead. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: preventing Activity from destroying
The service is picking up GPS locations; and sending to the server. Hence it needs to stay awake -- the server is tracking locations of the user on the web. On Fri, Sep 11, 2009 at 2:30 PM, Yusuf Saib (T-Mobile USA) yusuf.s...@t-mobile.com wrote: There are other ways to make a Service always work even if the phone sleeps; it depends on what your Service does. For example, if the Service's job is to respond to an Activity, then it is awake when the Activity is awake. Or if it responds to a broadcast Intent, ditto. Generally speaking, a Service that keeps the phone awake all the time to run like a daemon will eat up the battery, but there are cases where that's necessary. Why does your Service need to stay awake? Yusuf Saib Android ·T· · ·Mobile· stick together The views, opinions and statements in this email are those of the author solely in their individual capacity, and do not necessarily represent those of T-Mobile USA, Inc. On Sep 10, 10:15 pm, Jason shivi...@gmail.com wrote: John Yes, you are right. Pressing Home does call just onStop; while pressing Back calls onDestroy. Btw, how do you ensure that the service keeps running and doing its job even when the phone goes to sleep (power save mode)? I added PowerManager = pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MyService); wl.acquire(); but it didn't seem to help On Wed, Sep 9, 2009 at 8:26 PM, John P. johnny.d.p...@gmail.com wrote: It is true that when the Back button is pressed, onDestroy() is called. But hitting the Home button invokes the activity's onStop() for me. Now, it is true that if Android determines it needs memory, it may then invoke onDestroy() on the stopped activity. It sounds like if you want your activity to do something while minimized (i.e. in the background with no user interaction), then this logic should really be in your service. I wrote a program where a service continuously does some processing while keeping its state. I have an activity that binds to the service, gets the state, and appropriately rehydrates its own state accordingly. Everytime the activity pauses, it unbinds. Everytime it resumes, it rebinds. All the continuous processing is done on the service, and the activity gives the user a chance to modify the data. But when the activity is dead, the service continues on until I explicitly kill it through the said activity. On Sep 9, 10:01 pm, Jason shivi...@gmail.com wrote: How do I achieve the effect of 'minimizing' a UI activity? I have a UI activity that gets destroyed each time I click the Home, phone etc. keys on the phone. I would like the UI activity to be sent to the background; since it is bound to a service and processing the data returned by the service continuously. Clicking on the app ends up calling onCreate, onStart again. I would like to restart (onResume) instead. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: preventing Activity from destroying
Jason wrote: The service is picking up GPS locations; and sending to the server. Hence it needs to stay awake -- the server is tracking locations of the user on the web. Keeping the service alive all the time is very bad for the battery. I provide an analysis of this here: http://groups.google.com/group/android-developers/msg/36bf61dfb78ef4cc In your case, it will be substantially worse, as you are keeping the GPS radio on all the time. If a G1 lasts 8 hours in that state, I'd be impressed. I also cover the fallacy of keeping services alive all the time in a recent blog post: http://www.androidguys.com/2009/09/09/diamonds-are-forever-services-are-not/ -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Need Android talent? Ask on HADO! http://wiki.andmob.org/hado --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: preventing Activity from destroying
John Yes, you are right. Pressing Home does call just onStop; while pressing Back calls onDestroy. Btw, how do you ensure that the service keeps running and doing its job even when the phone goes to sleep (power save mode)? I added PowerManager = pm = (PowerManager) getSystemService(Context.POWER_SERVICE); WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, MyService); wl.acquire(); but it didn't seem to help On Wed, Sep 9, 2009 at 8:26 PM, John P. johnny.d.p...@gmail.com wrote: It is true that when the Back button is pressed, onDestroy() is called. But hitting the Home button invokes the activity's onStop() for me. Now, it is true that if Android determines it needs memory, it may then invoke onDestroy() on the stopped activity. It sounds like if you want your activity to do something while minimized (i.e. in the background with no user interaction), then this logic should really be in your service. I wrote a program where a service continuously does some processing while keeping its state. I have an activity that binds to the service, gets the state, and appropriately rehydrates its own state accordingly. Everytime the activity pauses, it unbinds. Everytime it resumes, it rebinds. All the continuous processing is done on the service, and the activity gives the user a chance to modify the data. But when the activity is dead, the service continues on until I explicitly kill it through the said activity. On Sep 9, 10:01 pm, Jason shivi...@gmail.com wrote: How do I achieve the effect of 'minimizing' a UI activity? I have a UI activity that gets destroyed each time I click the Home, phone etc. keys on the phone. I would like the UI activity to be sent to the background; since it is bound to a service and processing the data returned by the service continuously. Clicking on the app ends up calling onCreate, onStart again. I would like to restart (onResume) instead. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: preventing Activity from destroying
Jason wrote: I have a UI activity that gets destroyed each time I click the Home, phone etc. keys on the phone. By default, Android will not destroy your activity when you click the Home, phone etc. keys on the phone. There are only two ways I can think of for your described scenario to occur: 1. You are destroying it yourself via finish(). 2. You are leaking memory at a tremendous rate and Android needs to close it to reclaim memory. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Looking for Android opportunities? http://wiki.andmob.org/hado --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---
[android-beginners] Re: preventing Activity from destroying
It is true that when the Back button is pressed, onDestroy() is called. But hitting the Home button invokes the activity's onStop() for me. Now, it is true that if Android determines it needs memory, it may then invoke onDestroy() on the stopped activity. It sounds like if you want your activity to do something while minimized (i.e. in the background with no user interaction), then this logic should really be in your service. I wrote a program where a service continuously does some processing while keeping its state. I have an activity that binds to the service, gets the state, and appropriately rehydrates its own state accordingly. Everytime the activity pauses, it unbinds. Everytime it resumes, it rebinds. All the continuous processing is done on the service, and the activity gives the user a chance to modify the data. But when the activity is dead, the service continues on until I explicitly kill it through the said activity. On Sep 9, 10:01 pm, Jason shivi...@gmail.com wrote: How do I achieve the effect of 'minimizing' a UI activity? I have a UI activity that gets destroyed each time I click the Home, phone etc. keys on the phone. I would like the UI activity to be sent to the background; since it is bound to a service and processing the data returned by the service continuously. Clicking on the app ends up calling onCreate, onStart again. I would like to restart (onResume) instead. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Beginners group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~--~~~~--~~--~--~---