I have a background service in my android application.In which a thread listening recent tasks running frequently.My service overrides both onCreate()
and onStartCommand()
methods. When i tried to open some applications like Gallery
,Camera
etc..., the service will be stopped.It calls the onCreate()
method only and not onDestroy()
or onStartCommand()
.I tried to override onLowMemory() in this service but it logs nothing.The application saved internally by specifying
android:installLocation="internalOnly"
in the manifest file.
Note: This issue noticed on Micromax A54 2.3.5
.
Why does the background service stops sometimes? Is there any solution for this issue?
public class MyService extends Service {
public MyService() {
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
try {
if(intent != null){
//......
}
} catch (Throwable e) {
}
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onCreate() {
super.onCreate();
//......
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
And start the service like this
Intent intent = new Intent(getApplicationContext(), MyService.class);
getApplicationContext().startService(intent);