Android Question AlarmClock Class SET_ALARM vs. SET_TIMER

DaveB4A

Member
Licensed User
Longtime User
Hello all... I'm a brand new user trying to figure out something that is probably very simple - but I've read through the 555 pages of the new book - and I've searched the forums - and haven't been able to figure it out. So, if anyone could point me in the right direction, I'd appreciate it. :)

Essentially I found the forum post:

http://www.b4x.com/android/forum/threads/opening-default-clock-alarm-app.26437/#content

In that post, Erel gave an example of how to use the intent for SET_ALARM. That seems to work fine. However, in that same Java class (AlarmClock) there is also a SET_TIMER function.

http://developer.android.com/reference/android/provider/AlarmClock.html

What I'm trying to figure out is how to reference that function in B4A. I attempted:

B4X:
Sub SetTimer(TimerLength As Int)
  Dim i As Intent
  i.Initialize("android.intent.action.SET_TIMER", "")
  StartActivity(i)
End Sub

However, that results in the error:

B4X:
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.SET_TIMER flg=0x20000 (has extras) }

In essence, all I'm trying to do (in my first B4A app) is press a button and be "reminded" a fixed number of minutes later. As stated, SET_ALARM works - but if I use that I must remember to manually DELETE the alarm. So, I thought I might user the SET_TIMER instead - so that there would be nothing to DELETE once I was notified.

If anyone can point me in the right direction, I'd appreciate it.
 

DaveB4A

Member
Licensed User
Longtime User
Thank you for the help. Yes, that appears to be the problem. I had checked the documentation for "ACTION_SET_ALARM" which said "Added in API Level 9" and when I coded it using the "alarm" it worked fine (using a 4.1.2 Jelly Bean device, API 16)

Then, when I thought about using the "ACTION_SET_TIMER" instead, I also looked at the documentation but I didn't notice that it was "Added in API Level 19". Some days old age and bifocals make things more difficult than they need to be. :D

Anyway, thanks again for your help. I'll keep working on trying to figure out how to get the Alarm Manager's "cancel()" method to handle the "clean up" of old alarms.
 
Upvote 0
Top