-2

I am developing a hybrid application. I had used a plugin for track the location continuously using background service.

My problem is if I didn't use my application 2 days. The process is getting killed by itself. The status is changed to 0 process 1 service running. So cannot get location updates.

So how to resolve my issue? The below link is my location tracking plugin code for cordova.

https://github.com/selfservit/Track-Device-Location

techraf
  • 64,883
  • 27
  • 193
  • 198
Kalai Prakash
  • 141
  • 1
  • 8

1 Answers1

0

Android kills a service whenever it needs to clear memory. You can use START_STICKY in your service, but this also doesn't garauntee 100% that your service will start again after it's killed. I recommend using an AlarmManager to check wheather the service is running, and if it's not, restart the service.

Iman Irt
  • 145
  • 3
  • 12
  • what is the relation between service and process... what is the meaning of 0 process and 1 service running in running application..? – Kalai Prakash Sep 01 '16 at 06:48
  • am already using start _Sticky only in onstartcommand..and plz tell me how to use alarm manager in that/ – Kalai Prakash Sep 01 '16 at 06:50
  • Each process can have any number of services (in theory). Though I'm not sure what you mean by 0 process and 1 service running. – Iman Irt Sep 01 '16 at 07:09
  • Use the links to android documentation I provided in the answer to learn about how to use AlarmManager, also this is a code example I found useful: http://stackoverflow.com/questions/4459058/alarm-manager-example – Iman Irt Sep 01 '16 at 07:10
  • in settings-> applications-> running applications-> 0 process and 1 service running under my application.if i didn't use my application for long time that mean morethan 24 hours – Kalai Prakash Sep 01 '16 at 08:01
  • You can set the alarm manager to say... 10 minutes, and set it to check your service and restart it if it's stopped. By default, the intent that is passed to your service will be reset as well, so if you have not handled your data in the service lifecyle, the data will be lost and your service will start again. You can use IntentService class to keep the Intent data even when your service is killed – Iman Irt Sep 01 '16 at 08:52
  • it will checks 10 mins once whether the service is stopped means it will restart or else it will kept normal process only is it correct what i understand to ur statment. – Kalai Prakash Sep 01 '16 at 08:56
  • i have one more doubt??? my service is not stopping process only killed in that stituation also it will work ??? – Kalai Prakash Sep 01 '16 at 09:08