Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application crashes when application resume for long time

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?

like image 590
deepa Avatar asked Oct 08 '22 14:10

deepa


2 Answers

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.

like image 191
deepa Avatar answered Oct 12 '22 09:10

deepa


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.

like image 28
Adam Monos Avatar answered Oct 12 '22 09:10

Adam Monos