Reputation: 572
I have a Service that has to launch an external Activity. I would like that even after have launched the Activity, that Service will continue to be running. The problem is that the onDestroy() is invoked and the service is killed. here it is my code:
How I start the external Activity from inside the Service:
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
Any idea?
Upvotes: 1
Views: 159
Reputation: 1007554
Is it normal that when I start an activity from inside a Service, that Service is being killed?
Services are not "killed".
Your service will run until:
stopService()
referencing the service, orstopSelf()
, orbindService()
) are unbound (via unbindService()
), orHence, you need to determine which of the conditions is true. None necessarily have anything to do with starting an activity.
Note that starting an activity from a service is generally not a good idea, particularly if this may occur at arbitrary times rather than based on user input. Users dislike activities appearing out of nowhere.
Upvotes: 2