Starting Activity With Intent Flags Stops Service After It Starts

In my app, there’s an activity which leads to another through an intent with

Intent intent = new Intent(MainActivity.this, OtherClass.class);
startService(new Intent(MainActivity.this, Service.class));

The problem is the flags set on the intent makes it so that immediately after the onStartCommand() function is called in the service class, the onDestroy() function runs in the same service class. I need the flags set on the intent so that the user can’t back into the MainActivity. Does anyone know how I can achieve this effect without having the service stop?


I ended up calling finish() which, when used when starting intents, achieves the desired effect.

Leave a Reply

Your email address will not be published. Required fields are marked *