How can I get the application context from an Android Service?

You can use getApplicationContext() inside your service to get the application context.

Try using

getApplication().startActivity(i);

android start activity from service


Every Service has its own Context, just use the that. You don't need to pass a Service an Activity's Context.

No need for activity context in Service.

Intent i = new Intent(ctx, SONR.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);

Simply do as you do in Activity

Service and Activity both are subclasses of Context.


Change this:

Intent i = new Intent(ctx, SONR.class); 

to:

Intent i = new Intent(getApplicationContext(),SONR.class);

You're assertion that you need an application context to start an activity is inaccurate. You can start an activity from any context, including the service, which is a context.