I am trying to create a button that, when pressed, automatically creates an alarm in a mobile device set to a certain time specified earlier in the activity.
Namely, users select a time they want to wake up at using a TimePickerDialog and the “Create Alarm” button takes the calendar object the user “created” and sets an alarm for that time.
A lot of examples on the internet show how to do this in a separate activity, but I was hoping to find a way to do it without creating a new activity.
Is there a way to do this, or am I stuck having to create a new activity?
Thanks all.
You can definitely set the alarm inside the same activity. But I’m guessing this is not what you’re asking. If you want your alarm to trigger some code to run, even when your app is not in the foreground, then this code needs to be inside a receiver, not an activity. Activities only run when they are in the foreground. When you mention examples that use a “separate activity”, do you actually mean a receiver?
So, to answer the question that I think you were asking, the code to set the alarm will be in an activity class, while the code that runs when the alarm goes off will be in a receiver class.