所以我试图从我的onReceive函数在`BroadcastReceiver中开始一个新的活动,但是我似乎崩溃了。没有更多的理由,这里是代码:

public void onReceive(Context context, Intent intent) {

    //... other stuff that's not relevant

    Intent j = new Intent(context, myClass.class);
    context.startActivity(j);
    //If I comment the above two lines out and replace with a Toast, the toast shows up
}


有什么想法吗?

编辑-做了更多测试,我可以使用相同的意图从其他地方开始此活动。我只是无法通过BroadcastReceiver执行此操作...

谢谢。

最佳答案

尝试这个:

Intent j = new Intent(context, myClass.class);
j.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(j);

07-24 09:49
查看更多