StartActivity in android broadcast receiver

2019-05-13 19:28发布

I registered receiving SMS broadcast in manifest.xml. How can I start new Activity in receive() method of the broadcast. is there any flags of Intent to set or anything?

1条回答
干净又极端
2楼-- · 2019-05-13 20:05

use FLAG_ACTIVITY_NEW_TASK like this

@Override
public void onReceive(Context context, Intent intent)   {

    Intent i = new Intent(context, AlarmDialog.class);
    i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(i);    
}
查看更多
登录 后发表回答