开发者

Android - BroadcastReceiver's onReceive crashing from Intent?

So I'm trying to start a new activity from my onReceive function in a `BroadcastReceiver, yet I seem to be crashing. Without further adieu here is the code:

public void onReceive(Context context, Intent intent) {     

    //... other stuff th开发者_Go百科at'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
}

Thoughts?

Edit - did some more testing, and I can start this activity from other places using the same kind of intent. I just can't do it from the BroadcastReceiver...

Thanks.


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜