开发者

android: AlarmManager and activity life cycle

开发者 https://www.devze.com 2023-02-11 07:50 出处:网络
I decided to write simple alarm clock (using AlarmManager). When alarm works out I want to show simple dialog with 2 buttons: OK and Snooze. So I have a question: what should I connect with my Pending

I decided to write simple alarm clock (using AlarmManager). When alarm works out I want to show simple dialog with 2 buttons: OK and Snooze. So I have a question: what should I connect with my Pending Intent? I mean Service, Activity or BroadcastReceiver? At present version I use BroadcastReceiver where I start Activity that shows the dialog. I start it with flag FLAG_ACTIVITY_NEW_TASK. In onStrat() method I start music serv开发者_C百科ice. When OK button's pressed I call finish() for activity and stop music. In OnPause() I call finish() also. I do it because if two alarms run simultaneously then according to activity life cycle method onPause() will be called. It works... but sometime the music starts for a few seconds then finishes....then start again and finishes and so on. Why? Thanks.


So I have a question: what should I connect with my Pending Intent? I mean Service, Activity or BroadcastReceiver?

Probably an activity in this case. Theme your activity to look the way you want (e.g., Theme.Dialog) rather than fussing around with a regular dialog box.

It works... but sometime the music starts for a few seconds then finishes....then start again and finishes and so on. Why?

It is impossible to answer this question with the information you have supplied, sorry.

0

精彩评论

暂无评论...
验证码 换一张
取 消