Is it not possible to start an activity from BroadcastReceiver

前端 未结 2 1313
渐次进展
渐次进展 2021-01-26 23:43

I want to call this activity from a class extending BroadcastReceiver but its not working

Intent i = new Intent(DevicePolicyManager.ACTION_SET_NEW_PASSWORD);
co         


        
相关标签:
2条回答
  • 2021-01-27 00:28

    Add the FLAG_ACTIVITY_NEW_TASK flag to your intent, eg:

    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    
    0 讨论(0)
  • 2021-01-27 00:39

    Try this

    @Override
    public void onReceive(Context context, Intent arg1) {
        Intent intent = new Intent(context, yourclass.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }
    

    yourclass.class is your activity class that you want to start. Also, do not forget to add flags as new task.

    0 讨论(0)
提交回复
热议问题