Android的 - 广播接收器的距离的onReceive崩溃的意图? [英] Android - broadcastreceiver's onReceive crashing from intent?

查看:207
本文介绍了Android的 - 广播接收器的距离的onReceive崩溃的意图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想开始从我的onReceive功能的新活动在广播接收器,但我似乎崩溃。这里没有进一步再见是code:

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

公共无效的onReceive(上下文的背景下,意图意图){

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

}

思考?

编辑 - 做了一些更多的测试,我可以用同一种意图开始从其他地方这一活动。我只是不能从广播接收器做...

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...

感谢。

推荐答案

试试这个:

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

这篇关于Android的 - 广播接收器的距离的onReceive崩溃的意图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆