1

I am developing an android application related to gps. that is sending location information periodically to the server. sometime i am getting process killing issue in some devices.

if my application running in foreground then its working file. but while we minimize app and move it to back or once phone going to sleep then app automatically clearing all application data and variables. and then when we tried to resume activity back, it showing blank information and generating exception.

how to prevent clear app data while app running in backgtound? i want to keep this information as it is. this issue only arise in some devices not all.

i have also tried research on Google, but not getting any good solution.

Please Help me. Thank you.

Ajay
  • 1,189
  • 1
  • 12
  • 28
  • Android should not be clearing properly stored application data or permitting another app to do that - it is something that should happen only on uninstall or from the settings menu. If users of legacy android devices with broken security have ill-conceived apps installed which are wiping out your data, you might pop up an AlertDialog on next run and explain why they shouldn't be doing that to you. Of course the other possibility is that you are not properly persisting your data - how are storing it? You should indeed expect that your app's process can die, especially when in the background. – Chris Stratton Feb 25 '15 at 13:27
  • @Ajay You mean the data stored in `Application class` is getting cleared? if so, it is not a good approach to store data in application class. Refer this article : http://www.developerphil.com/dont-store-data-in-the-application-object/ – Abhishek V Feb 26 '15 at 09:14
  • @AbhishekV : yes you are right. but i need that information only within the application scope. once app close, then all information should be clear. i think i have to go for SharedPrefrences. right? – Ajay Feb 26 '15 at 10:31
  • Yeah..SharedPreferences seems to be the better approach. – Abhishek V Feb 26 '15 at 10:34

1 Answers1

0

You can't do it like that. If you want your application to keep sending data to a remote service even if the app is in the background, you need to do it a long running Service. Keep in mind that a service runs by default in the main thread, so you need to run your comms with the server in a background thread (however you like it, asynctask, wtv). Then, to really make sure Android doesn't kill your service if it's running low on memory, you need to set your service as a foreground service with a notification.

That way, even if your app is sent to the background you're sure Android the communication will continue.

Joao Sousa
  • 4,055
  • 1
  • 26
  • 29