I have an app with a service. This service should be started if the smartphone is rebooted. Anyway if the app was started during the switch off or not. And the app should be restarted (or still running) if the app is swiped away (killed). This work on my Smartphone with Android 4.2, but doesn't work on a Smartphone with Android 5.1.
I start my service in a class, derived from BroadcastReceiver:
@Override
public void onReceive(Context oContext, Intent oIntent)
{
if (oIntent.getAction().equalsIgnoreCase(Intent.ACTION_BOOT_COMPLETED)) {
Intent oNewIntent = new Intent(oContext, CarFinderService.class);
// class can be anything which you want to start on bootup...
oNewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
oContext.startService(oNewIntent);
}
}
This works on Android 4.2., but not on Android 5.1. I thins this code is OK. Or not?
What can I do that a service is started on reboot or if the app is swiped away?
I tried different things, found via searching the web. But I found a solution who works on Android 5.1.
Any hints?
Thanks Hans