I want to run my service even when the app killed from background task. can anyone give me some suggestion please. (Work fine when I minimize the app)
here my code :
public class MyService extends Service {
private BroadcastReceiver mReceiver = null;
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public void onCreate() {
final IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
mReceiver = new ScreenReceiver();
registerReceiver(mReceiver, filter);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (ScreenReceiver.wasScreenOn) {
Log.e("MYAPP", "SCREEN TURNED OFF");
} else {
// this is when onPause() is called when the screen state has not changed
}
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
}
}