Starting an Activity from BroadcastReceiver in Service

前端 未结 2 1132
感动是毒
感动是毒 2021-01-29 01:21

I am trying to start an activity at a certain time with the help of a service and broadcastreceiver. The problem is, once the time hits, my app crashes.

Here\'s my Alarm

2条回答
  •  遥遥无期
    2021-01-29 01:47

    To start an Activity outside of an Activity Context you need to use the flag FLAG_ACTIVITY_NEW_TASK. Add this to your Intent

     Intent in = new Intent(this, GoTime.class);
     in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    

    if this doesn't solve your problem then please post the logcat.

    Intent

提交回复
热议问题