-1

I Want to run background service for give me location of user but when I destroy or lock mobile screen, service are killed, it shows nothing. I hope any one had idea about it. please Share.

Sensor Service

matdev
  • 4,115
  • 6
  • 35
  • 56
Aakarsh Rai
  • 1
  • 1
  • 4

1 Answers1

0
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    super.onStartCommand(intent, flags, startId);
    Log.d(TAG, "onStartCommand");
    ... 
    return START_STICKY;
}

Did you try START_STICKY?

tadev
  • 204
  • 1
  • 5
  • Yes @Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); Context context = getApplicationContext(); Log.i("START", "onStartCommand!"); startTimer(context); return START_STICKY; } and in startTimer i set timing and call webservice for insert location – Aakarsh Rai Sep 18 '19 at 07:33
  • START_STICKY has nothing to do with this problem – Vladyslav Matviienko Sep 18 '19 at 07:40
  • @VladyslavMatviienko but service are not run in background after destory and data were not punch in service. :( – Aakarsh Rai Sep 18 '19 at 08:11
  • @AakarshRai that's right, and as I said - `START_STICKY has nothing to do with this problem` – Vladyslav Matviienko Sep 18 '19 at 08:24
  • please check [link](https://stackoverflow.com/questions/34222943/how-to-restart-service-after-the-app-is-killed-from-recent-tasks/34223274) – tadev Sep 18 '19 at 08:32
  • @VladyslavMatviienko But Couldn't get where is problem used all relevant code regarding this... – Aakarsh Rai Sep 18 '19 at 10:44
  • @tadev I am taking location gps provider it give me lat long but problem is arise service doesn't insert values in Server. – Aakarsh Rai Sep 18 '19 at 10:50