Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Android Alarm App Questions.

Hey!

So recently I have been following the Android track and I have been really enjoying it. I just finished creating the Fun Facts app and I decided that before carrying on with the track and creating the blog reader app I would try and make an app on my own. I decided to choose an Alarm App with some challenges as I sometimes have trouble waking up on time!

However, after crawling through the documentation on the android developer site and looking on Stack Overflow I cannot seem to find how to set up the Alarm to go off.

I have the hour and minute stored in variables so that is all working perfectly but I don't know how to use them to set off an alarm at a certain time.

Any help would be much appreciated and I hope you're all having awesome days!

-Luke

1 Answer

Not sure if this might work but just a quick idea

  • in a separate method set a media player Android guide to media player

  • in your project resource add some .mp3 files and add it through the media player method above

  • use a current time method that returns the system time. Something like from the android.text.format.Time class

Time now = new Time();
now.setToNow();
  • next get an input from the user for when he would like the alarm to be set (lst assume for its only the next day, to make things simple at this stage). Use quick calculations to find the difference.

  • Then put a check condition to see if the calculated time (time for which the alarm is due - current time at which the alarm was set)

  • Once the condition is met call the media player method and it will play the sound

  • Maybe as a suggestion add a snooze button that will unregister the media player file (we all need that snooze button :D )

Not sure if its the prefect idea. But something to work on. Hope this idea helps

Hey Gunjeet.

Thank you for the ideas! Sounds like your idea would work well but I need the phone to unlock when the Alarm is going off and for a screen to display.

I was looking through the documentation and thought that the Alarm Manager and the Alarm Clock might be useful but after reading the information I still struggle to know how to use them well.

-Luke

Hi Luke,

You might want to check this link if you haven't Alarm Clock Tutorial

Maybe the description of usage might spark off an idea for you

  • Gunjeet

Thanks for the link I have taken a look at the tutorial and even after reading the description of the code I still feel a tad confused.

I'm thinking maybe this application is a bit too complex for me too understand at this moment in time.