I want to create a service
that runs even when the app is closed from the Task manager. I have created a service and then Logged a message to check if it's running and I noticed that it works only if if the app is running or in foreground.
Service class:
public class CallService extends Service {
private final LocalBinder mBinder = new LocalBinder();
protected Handler handler;
public class LocalBinder extends Binder {
public CallService getService() {
return CallService .this;
}
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
@Override
public void onCreate() {
super.onCreate();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("TESTINGSERVICE", "Service is running");
}
}
Starting the service from my MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
startService(new Intent(this, CallService.class));
Manifest
<application>
...
<service
android:name=".activities.services.CallService">
</service>
</application>
What changes do I have to make? Thanks, folks