user878521
user878521

Reputation: 13

I want to call the start Activity in BroadcastReceiver in android

I want to call the start Activity in BroadcastReceiver in android. I know it is a service and we cant call an activity from a service.

Upvotes: 0

Views: 454

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006704

I want to call the start Activity in BroadcastReceiver in android.

Call startActivity() on the Context passed in as a parameter.

I know it is a service

A BroadcastReceiver is not a Service.

and we cant call an activity from a service.

Yes, you can call startActivity() in a Service.

However, calling startActivity() from either a BroadcastReceiver or a Service may not be what the user wants. You have no idea what the user is doing, and you might be taking over the foreground in the middle of something else. Please only use this in places where the user will value the interruption, or offer alternatives (e.g., a SharedPreference to indicate that you should use a Notification instead of starting an activity).

Upvotes: 3

Related Questions