tags:

views:

112

answers:

1

Is it possible to start an Activity from a Service? If yes, how can we achieve this?

+5  A: 

android.app.Service is descendant of android.app.Context so you can use startActivity directly. However since you start this outside any activity you need to set FLAG_ACTIVITY_NEW_TASK flag on the intent.

For example:

Intent i = new Intent();
i.setClass(this, MyActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);       

where this is your service.

Marcin Gil