Go Back   Android Forums > Android Development > Application Development
Application Development Dev Lounge for the Coder Folks
Gamers - Check out our new sister sites!
Nintendo Wii U!    |    OUYA - $99 Android System!

test: Reply
 
LinkBack Thread Tools
Old September 15th, 2010, 07:12 PM   #1 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Apr 2010
Posts: 15
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default multitasking problems

seems like a number of my users experience crashes when resuming the back-grounded app. I'm not sure how to repeat the crash but it seems to be very much related to the state of the operating system.

What happens is that some of my arrays bound to static memory go null. But there is no possible way for that to occur in any state in my app. The only way it could occur if it it skipped my first activity (which initializes them) and they jump to a later activity.

When apps come back into the forground, could the OS clear out memory if it decides the app is no longer worthy of taking up resources and it gets paged out, then dump you to the last activity you left off on? In order words, could my global variables be destroyed or compromised and then my app tries to load the last activity the user left off on (not necessarily the first activity) therefore creating a state that is will crash my app?

lms5400 is offline  
Reply With Quote
Sponsors
Old September 15th, 2010, 08:12 PM   #2 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Apr 2010
Posts: 15
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

upon further testing, i think its an issue with 2.2 only. I was able to get it to crash on resume in a 2.2 simulator (and on the phone) but no other supported versions or phones had issues that i know of.

Does 2.2 have issues?
lms5400 is offline  
Reply With Quote
Old September 17th, 2010, 09:18 AM   #3 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,925
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 463 Times in 286 Posts
Default

If you are using deprecated methods, there is a possibility that one or more of the deprecated methods in use are no longer supported by the OS. This is the reason that a lot of apps required an update on release of 2.2.
jonbonazza is online now  
Reply With Quote
Old September 17th, 2010, 01:48 PM   #4 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 315
 
Device(s): Samsung Galaxy Nexus
Carrier: Not Provided

Thanks: 0
Thanked 52 Times in 51 Posts
Default

I think this is androids doing. If the application is kept in the background for so long that the system needs its resources elsewhere, Android kills the process. And when user wants to use the application again, the application is given a new process, but the content in memory is lost.
I'm not sure about this, so don't shoot me if I'm wrong.
miXer is offline  
Reply With Quote
Old September 20th, 2010, 01:05 PM   #5 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Apr 2010
Posts: 15
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

i'll look for deprecated functions, but shouldn't i get waring about that?

As far as android paging out my app.... if it decides it needs resources, it might put it to to the SD memory right? Then when i need it, it pages it back in, this is standard OS virtual memory management. If for some reason if it decides my app needs to be closed and never come back, why would it try to resume on the screen it last left off - should it not just start over? I'm totally confused. I'm pretty sure this is not an issues with my code (but i have been wrong many times about that point, lol). But i'm at least 100% sure static memory array objects are being null'ed for no reason on resume which is very disturbing.
lms5400 is offline  
Reply With Quote
Old September 21st, 2010, 03:29 AM   #6 (permalink)
Member
 
Join Date: Aug 2010
Location: Norway
Posts: 315
 
Device(s): Samsung Galaxy Nexus
Carrier: Not Provided

Thanks: 0
Thanked 52 Times in 51 Posts
Default

Android Component Lifecycle
miXer is offline  
Reply With Quote
Old September 21st, 2010, 09:41 AM   #7 (permalink)
Junior Member
 
Join Date: Sep 2010
Posts: 21
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 2 Times in 1 Post
Default How to fix a crashed app!

Quote:
Originally Posted by lms5400 View Post
seems like a number of my users experience crashes when resuming the back-grounded app. I'm not sure how to repeat the crash but it seems to be very much related to the state of the operating system.

What happens is that some of my arrays bound to static memory go null. But there is no possible way for that to occur in any state in my app. The only way it could occur if it it skipped my first activity (which initializes them) and they jump to a later activity.

When apps come back into the forground, could the OS clear out memory if it decides the app is no longer worthy of taking up resources and it gets paged out, then dump you to the last activity you left off on? In order words, could my global variables be destroyed or compromised and then my app tries to load the last activity the user left off on (not necessarily the first activity) therefore creating a state that is will crash my app?
I know exactly what's going on. Your static variables ARE going null because the phone is killing your app's process while the user is in a different app. This happened to us a lot on the Android app that we created. Also, you'll never want to carry around static variables if you don't have to. With the way Android allows you to pass things around from and to activities with intents and such, there shouldn't be a need for statics.

In either case, to fix your problem, have your Activity override the onSavedInstanceState(Bundle) method. Use the passed in bundle to store all the data that you want to have retained in the case the Android OS kills your app.

If the OS does kill your app, the OS will restart the app in the same activity that it was previously at, and will actually AGAIN go through your onCreate(Bundle). Guess what this bundle is? It's the same bundle that you saved data into from onSavedInstanceState(Bundle). Use this bundle to replace the arrays that are going null and possibly any other fields that you might need.

As a note, the onSavedInstanceState(Bundle) method is called by the ActivityManager when your app goes into a state where it is killable. Refer to the Android Activity Lifecycle linked above to see when your app can be killed. The ActivityManager calls this as an effort to save the necessary data in the case it will kill your app.

Note: This happened to us also with crashing, and while it is unrelated to the problem at hand, may help someone. If you have to reinflate dynamically added layouts because of a crashed app, do so in the onPostCreate() method. If we did it in onCreate(Bundle), then for some reason (even though we had it inflating new versions of the layout every time), there seem to be an issue with references getting mixed up and changes to one would affect changes to all the layouts. *Just a side note :P*
DavidAndroidDev is offline  
Reply With Quote
Old September 21st, 2010, 03:41 PM   #8 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Apr 2010
Posts: 15
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you, that was very helpful! I'll look into passing around variables. One of the issues I had with that last time i briefly looked into it was I thought for some reason only basic datatypes were allowed to be passed around with the bundle class such as integer, boolean, string, etc, and my custom objects were not?
lms5400 is offline  
Last edited by lms5400; September 21st, 2010 at 03:44 PM.
Reply With Quote
Old September 22nd, 2010, 12:09 AM   #9 (permalink)
Junior Member
 
Join Date: Sep 2010
Posts: 21
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 2 Times in 1 Post
Default

In order for your custom objects to be passed around through intents and such, you class must implement the Parcelable interface. If you implement this, your class implements a WriteToParcel() method and a describeContents method. For describeContents, just have it return zero. For the WritetoParcel method, use the parcel parameter to store each of the fields in your object. pay attention to the order! if you lok at the java doc for Parcelable, it has a code example check out the Parcelable.CREATOR. copy it! Then change all the types on the Creator to your object. The two methods inside the creator, newArray(), which should just return your object returned as an array with the size parameter. The other, allows you to "unmarashall" the parcel to your object. Typically, I let my class have a constructor that takes aparcel. remember the order? Read the values from the parcel back in in the same.order it was written out.
DavidAndroidDev is offline  
Reply With Quote
Old September 24th, 2010, 07:32 PM   #10 (permalink)
Junior Member
Thread Author (OP)
 
Join Date: Apr 2010
Posts: 15
 
Device(s):
Carrier: Not Provided

Thanks: 0
Thanked 0 Times in 0 Posts
Default

perfect, you have been very helpful!
lms5400 is offline  
Reply With Quote
Sponsors
Reply


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 03:02 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.