Issue
I'm trying to start an activity from a class that extends BroadcastReceiver.
public void onReceive(Context context, Intent intent) {
the problem is that parameter context is the Application context and not an Activity context.
Is there a way start an intent using the Application context?
Solution
Here is sample code how to call another activity using context, set flag as per your requirement:
public void onReceive(Context context, Intent intent) {
Intent intent = new Intent();
intent.setClass(context, xxx.class);
intent.setAction(xxx.class.getName());
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
context.startActivity(intent);
}
Answered By - SBJ
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.