How do you start an Activity with AlarmManager in Android?

前端 未结 8 919
鱼传尺愫
鱼传尺愫 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条回答
  • 2020-12-01 17:37

    you are not sending any broadcast for the receiver to receiver and further more it lokks like u want a splash screen or something like that for that purpose u can start a new thread wait for some sec then start ur activity in that and for that time period u can do what ever u want on the UI thread ...

    0 讨论(0)
  • 2020-12-01 17:41

    How do you use AlarmManager (in the Android API) to start an Activity at a given time?

    Supply a PendingIntent to the set() call that identifies the activity to start up. Or, do what you're doing, which should work just fine.

    This sample project is a bit elaborate, because it's 19 tutorials deep into one of my books, but if you look at classes like EditPreferences, OnBootReceiver, and OnAlarmReceiver, you will see the same basic recipe that you're using above. In this case, I could have just used a getActivity() PendingIntent, but the tutorial after this one gives the user a choice of launching an activity or displaying a Notification, so a BroadcastReceiver makes more sense.

    Look for warnings in addition to errors in LogCat. Most likely, your receiver or activity is not in your manifest.

    Note that popping up an activity out of the middle of nowhere is generally not a good idea. Quoting myself from the book in question:

    Displaying the lunchtime alarm via a full-screen activity certainly works, and if the user is looking at the screen, it will get their attention. However, it is also rather disruptive if they happen to be using the phone right that instant. For example, if they are typing a text message while driving, your alarm activity popping up out of nowhere might distract them enough to cause an accident. So, in the interest of public safety, we should give the user an option to have a more subtle way to remind them to have lunch.

    0 讨论(0)
提交回复
热议问题