开发者

Calling APNdroid from broadcast reciever force close

I am trying to write an app that calls APNdroid from a broadcast receiver. I have checked out the APNdroid project from "google code", added it to my project's "Build path" and imported the necessary classes ("Constants' and "IActionService'). From my BroadCast receiver I am starting the activity like so:

Intent APNintent = new Intent(Constants.CHANGE_STATUS_REQUEST);
    int onState = Constants.STATE_ON;
    intent.putExtra(Constants.TARGET_MMS_STATE, onState);
    intent.putExtra(Constants.TARGET_APN_STATE, onState);
    context.startActivity(APNintent);

However, 开发者_JS百科when I start my app, it gets "Force Closed". Does anyone have any idea what I am doing wrong? Do I need to define something in the manifest file?

Thank you.


I found the answer looking for "how to call and activity from a broadcast receiver". I turns out I am missing a flag that should be added when launching an activity from a broadcast receiver. The missing flag is: "FLAG_ACTIVITY_NEW_TASK" The code looks like this:

Intent APNintent = new Intent(Constants.CHANGE_STATUS_REQUEST);
int onState = Constants.STATE_ON;
intent.putExtra(Constants.TARGET_MMS_STATE, onState);
intent.putExtra(Constants.TARGET_APN_STATE, onState);
APNintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(APNintent);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜