Reputation: 2494
I am creating an android application. It holds a downloading process from server. It's running fine until the application runs and maintains the data without any crashes, but now I am stuck up with the problem as described below
When the application minimizes by pressing home button and after a long time, when I open the application all the data in the application are deleted. It gives me a "Null Pointer Exception"; even the ArrayList value are deleted and it gives a 0 sized arraylist.
I am opening the application after maximizing from the home screen through OnResume only, but it didn't call itself.
I don't know why this problem occurs. Can anyone please suggest me a solution and point me what am I doing wrong?
Upvotes: 5
Views: 5061
Reputation: 2494
Yes, it's true - as @paradx said - that the Garbage Collector throws away the data while the app is in background. Finally I found a solution based on @paradx suggestion, as data are stored in SQLite or savedInstanceState
Just pass some of static values through the
intent.putExtra("static key","static value");
Then static hashmap are written in a file and retrieved for later use. Now the application does not crash for this problem.
I have posted this solution so that someone might use it.
Upvotes: 3
Reputation: 4297
My guess is, that the garbage collector throws away your data while your app is in the background. try saving your data either to the built in SQLite database, or to the savedInstanceState bundle in the onSaveInstanceState() lifecycle method and load it back in the onRestoreInstanceState() method.
Upvotes: 1
Reputation: 4199
Did u use the apache HTTP client or the UrlConnection?
See Apache http client or URLConnection
Maybe the wrong use could lead to such an NPE. Could you also please post your logCat output?
Upvotes: 0