5

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?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
deepa
  • 2,496
  • 1
  • 26
  • 43

3 Answers3

3

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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
deepa
  • 2,496
  • 1
  • 26
  • 43
1

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.

Adam Monos
  • 4,287
  • 1
  • 23
  • 25
0

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?

Community
  • 1
  • 1
Thkru
  • 4,218
  • 2
  • 18
  • 37
  • There is no problem in downloading..its working fine.. At the maximizing of app itself crashes..since it shows the values maintain throughout the application are deleted. – deepa Jun 07 '12 at 13:21
  • maybe you should run that stuff in a single service to ensure it does not get deleted in the background. Could you please provide the logcat output? – Thkru Jun 07 '12 at 13:23
  • are you minimizing it while downloading is in progress? – Vipul Jun 07 '12 at 13:25
  • no in downloading there is not a problem.. only the data throughout the application are lost.. – deepa Jun 08 '12 at 05:11