开发者

Regarding broadcast receiver android

开发者 https://www.devze.com 2023-03-10 08:52 出处:网络
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 co

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

精彩评论

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

关注公众号