Li Hanying
Lurker
I'd like to get the location data in the background.
So I used service. But it stopped when the app closed.
This is my code.
in the manifest.xml
<service
android:name=".services.MyService"
android:exported="true"
android : process=":MyLocationService" />
in the service.java
@override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
and the main activity I called the startservice.
Intent intent = new Intent(this, MyService.class);
startService(intent);
It works well in the background and foreground of the app, But it stopped when the app closed.
I wanna running service after app is closed.
Thank you.
Regards.
Li.
So I used service. But it stopped when the app closed.
This is my code.
in the manifest.xml
<service
android:name=".services.MyService"
android:exported="true"
android : process=":MyLocationService" />
in the service.java
@override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);
return START_STICKY;
}
and the main activity I called the startservice.
Intent intent = new Intent(this, MyService.class);
startService(intent);
It works well in the background and foreground of the app, But it stopped when the app closed.
I wanna running service after app is closed.
Thank you.
Regards.
Li.