开发者

Regarding broadcast receiver android

Can an activity be invoked using a Broadca开发者_运维知识库stReceiver? The onReceive for BroadCast receiver will be triggered whenever the user presses the power button.


Yes we can invoke try below code

Intent mIntent = new Intent(getBaseContext(), Activity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplication().startActivity(mIntent);


You can start the activity from BroadcastReceiver in the following way

public void onReceive(Context context, Intent intent) {
    Intent intentStart = new Intent(context, StartActivity.class);
    intentStart.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(intentStart);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜