Re: [android-developers] Re: Clearing the RAM is not closing the whole application (i.e. all the activities)
On Tue, Jul 17, 2012 at 6:48 AM, xoom wrote: > Actually when I clear the RAM from task manager it clears all the memory of > my application including some global variables shared between the > activities. And when the activity restarts I am getting null pointer > exceptions because this global variables are getting cleared. One way is to > store the application state in bundle but is there any other way? > > If my whole application is closed then its fine, no need to preserve the > application state also. Your "whole application is closed" in all cases you have cited here. Your process is being terminated by the task manager, as you can tell by the fact that your global variables have been cleared. Your problem is that you are assuming that those global variables always exist and that users are always coming into your application through one path that sets up those variables. That is not necessarily a valid assumption -- recent tasks is just one example of a way the user can "deep link" elsewhere in your application. One way or another, you need to handle the case where users return to your app, running in a fresh process, but are not coming into your launcher activity. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 3.8 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: Clearing the RAM is not closing the whole application (i.e. all the activities)
Well, this would be one of many reasons that global variables should be avoided like the plague wherever possible... The correct thing to do would be to save you're application state in onSaveInstanceState() and restore it in onRestoreInstanceState() On Jul 17, 2012 4:50 AM, "xoom" wrote: > Thanks Richard for the reply. > Actually when I clear the RAM from task manager it clears all the memory > of my application including some global variables shared between the > activities. And when the activity restarts I am getting null pointer > exceptions because this global variables are getting cleared. One way is to > store the application state in bundle but is there any other way? > > If my whole application is closed then its fine, no need to preserve the > application state also. > > On Tuesday, July 17, 2012 4:06:21 PM UTC+5:30, RichardC wrote: >> >> You need to cope with just your top activity being kill anyway so why is >> this a problem? >> >> On Tuesday, July 17, 2012 10:18:00 AM UTC+1, xoom wrote: >>> >>> >>> Hello all, >>> >>> I have 50 + activities in my application. Application is built for >>> android version 2.0 onwards android devices. Everything is working fine on >>> 2.x and 3.x android running devices but there is a strange problem >>> happening on 4.x running android devices. >>> >>> On 4.x device, after starting my app if I clear the RAM from the task >>> manager i am getting an application crash. I checked the logcat prints and >>> I found that when I clear the RAM, android kills my current running >>> activity only (i.e. first in the activity stack). I checked the >>> documentation and as per the documentation android should close the whole >>> app (i.e. with the whole activity stack). But the same is not happening on >>> 4.x devices. Unlike 4.x, 2.x and 3.x devices kills all the parent >>> activities as well and because of that the app works without any issue on >>> 2.x and 3.x devices. >>> >>> I am getting lots of crashes in my app because of this changed behavior. >>> Is there anything I need to do in my app to handle this specifically for >>> 4.X android versions. >>> Please help me to solve the issue it is giving lot of trouble to me. >>> >>> -- > 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 -- 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: Clearing the RAM is not closing the whole application (i.e. all the activities)
Thanks Richard for the reply. Actually when I clear the RAM from task manager it clears all the memory of my application including some global variables shared between the activities. And when the activity restarts I am getting null pointer exceptions because this global variables are getting cleared. One way is to store the application state in bundle but is there any other way? If my whole application is closed then its fine, no need to preserve the application state also. On Tuesday, July 17, 2012 4:06:21 PM UTC+5:30, RichardC wrote: > > You need to cope with just your top activity being kill anyway so why is > this a problem? > > On Tuesday, July 17, 2012 10:18:00 AM UTC+1, xoom wrote: >> >> >> Hello all, >> >> I have 50 + activities in my application. Application is built for >> android version 2.0 onwards android devices. Everything is working fine on >> 2.x and 3.x android running devices but there is a strange problem >> happening on 4.x running android devices. >> >> On 4.x device, after starting my app if I clear the RAM from the task >> manager i am getting an application crash. I checked the logcat prints and >> I found that when I clear the RAM, android kills my current running >> activity only (i.e. first in the activity stack). I checked the >> documentation and as per the documentation android should close the whole >> app (i.e. with the whole activity stack). But the same is not happening on >> 4.x devices. Unlike 4.x, 2.x and 3.x devices kills all the parent >> activities as well and because of that the app works without any issue on >> 2.x and 3.x devices. >> >> I am getting lots of crashes in my app because of this changed behavior. >> Is there anything I need to do in my app to handle this specifically for >> 4.X android versions. >> Please help me to solve the issue it is giving lot of trouble to me. >> >> -- 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: Clearing the RAM is not closing the whole application (i.e. all the activities)
You need to cope with just your top activity being kill anyway so why is this a problem? On Tuesday, July 17, 2012 10:18:00 AM UTC+1, xoom wrote: > > > Hello all, > > I have 50 + activities in my application. Application is built for android > version 2.0 onwards android devices. Everything is working fine on 2.x and > 3.x android running devices but there is a strange problem happening on 4.x > running android devices. > > On 4.x device, after starting my app if I clear the RAM from the task > manager i am getting an application crash. I checked the logcat prints and > I found that when I clear the RAM, android kills my current running > activity only (i.e. first in the activity stack). I checked the > documentation and as per the documentation android should close the whole > app (i.e. with the whole activity stack). But the same is not happening on > 4.x devices. Unlike 4.x, 2.x and 3.x devices kills all the parent > activities as well and because of that the app works without any issue on > 2.x and 3.x devices. > > I am getting lots of crashes in my app because of this changed behavior. > Is there anything I need to do in my app to handle this specifically for > 4.X android versions. > Please help me to solve the issue it is giving lot of trouble to me. > > -- 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