Starting an Activity from BroadcastReceiver in Service

前端 未结 2 1172
感动是毒
感动是毒 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:42

    I would like to point out that starting activities from the background is not a great experience for the user. Suppose the user is in the midst of some other work? Arbitrarily starting a new Activity is at the very least an annoyance.

    I think that what you should do is send a notification from your Service, with a content Intent leads to the activity you want to start. This gives users the choice to go to the activity as soon as the notification appears or wait until they're finished with their current work before going to the activity.

    Perhaps I've misunderstood what you want to do, but you may want to consider amending your app design.

    The Notifications API guide discusses this in more detail. There's also an Android training class called Notifying the User

提交回复
热议问题