I have to get people\'s trajectory (from home to job, for example), so my app gets latitude and longitude (I have two buttons: 1. Start to get lat and lon 2. Stop to get la
Try our this
public class ForegroundService extends Service {
private static final String LOG_TAG = "ForegroundService";
@Override
public void onCreate() {
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Your logical code here
return START_STICKY;
}
@Override
public void onTaskRemoved(Intent rootIntent) {
//When remove app from background then start it again
startService(new Intent(this, ForegroundService.class));
super.onTaskRemoved(rootIntent);
}
@Override
public void onDestroy() {
super.onDestroy();
Log.i(LOG_TAG, "In onDestroy");
}
@Override
public IBinder onBind(Intent intent) {
// Used only in case of bound services.
return null;
}
}
On Start button click:
Intent startIntent = new Intent(MainActivity.this, ForegroundService.class);
startService(startIntent);
In Manifest