How do you start an Activity with AlarmManager in Android?

前端 未结 8 917
鱼传尺愫
鱼传尺愫 2020-12-01 17:01

I\'ve poured through a dozen tutorials and forum answers about this problem, but still haven\'t been able to get some working code together. I\'ll try to keep the question s

8条回答
  •  萌比男神i
    2020-12-01 17:22

    Main Problem : if you close completely you're app and expect to start you're activity after 3 seconds, you wrong. because when you close you're app , you're app cant receive broadcast, for solve this problem use services instead of broadcasts.

    Point: when you're service would ran ,you cant start your activity if your app wouldn't in foreground.

    Solution: I think when your service started you can again set Alarmmanager to start your activity with PendingIntent for just now.

    Remember :

    1. When you create your intent for pass it to pendingIntent add the FLAG_ACTIVITY_NEW_TASK to it.
    2. For this PendingIntent use PendingIntent.getActivity() method and for the first PendingIntent use PendingIntent.getService() method.

    I hope this help you.

提交回复
热议问题