In my application i have a listView.
I populated this listView 10 items at a time.
So, i fetch the 1st 10 items in the background when i am showing a spalsh screen. and once the splash screen goes away user can see the 1st 10 items.
Now in the Activity which contains this listView i wrote something like this:
onLastItemReached(){
getNextten();
}
works fine. and when i am going to someother activity from this listViewActivity i set the flag so that all the items browsed till then will be retained when back is pressed(i mean if user scrolled down to 100 items and clicked one item and went to some activity and clicks device back button, he will be shown the 100th item and the rest 99 items doesn’t need to be fetched again)
the problem is when i close the application and open it after some 5-10 mins it gets crahsed saying:
ArrayIndexOutOfBoundsException
if i am reopening it in 1-3 mins it works fine.
Sorry i cannot post any code because all the activity has around 800 lines.
Any one has any idea why i get this exception always. and 1 thing i want to know is, is there anything like if an app is in background for more than 5 mins remove all its data
Edit:
my closing my application, i mean when i am on the ListView Screen i press Home button, reopen the app after 5-10 mins
This is the StackTrace i get, I was trying to Handle unCaughtExceptions:
threadid=1: thread exiting with uncaught exception (group=0x40020660)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.Android.WiC_MobileApp/com.Android.WiC_MobileApp.FeedListViewActivity}: java.lang.ArrayIndexOutOfBoundsException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1728)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1747)
at android.app.ActivityThread.access$1500(ActivityThread.java:155)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
So after looking at my log cat it says the error is at line 201, and that line contains:
Log.d("array of product names", SplashActivity.products_array[0] + "--"
+ SplashActivity.products_array[1]);
This is an array populated in SplashActivity and made public static.
This could actually happen within 1 minute. It’s just dependent on the environment that the system is running on. When you press the home button (or back button on the top activity) the system will put your app in a hibernation sort of mode. It keeps it in memory until that memory is needed. This allows the user to quickly go back to it on the event that they simply wanted to switch real quick and go back. After a few minutes though, if the user opened up a game or something, the OS may decide to wipe the app from memory. In which case, when the user reopens your app, you have to rebuild everything from scratch.
The reason your app crashes is because you’re trying to retrieve the element before the app has actually rebuilt the ListView. If the app is still in memory, it works because everything is still built. If the app was removed, then the list must be rebuilt, re-inflated, or whatever. Then you try to retrieve the element.