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);
}
精彩评论