Ajay
Ajay

Reputation: 1189

prevent app to clear application data while running in background

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.

Upvotes: 1

Views: 1462

Answers (1)

Joao Sousa
Joao Sousa

Reputation: 4123

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.

Upvotes: 0

Related Questions