November 15th, 2011, 04:06 PM
|
#2 (permalink)
|
|
New Member
Join Date: Jan 2010
Posts: 12
Device(s):
Thanks: 1
Thanked 0 Times in 0 Posts
|
Assuming you know the basics of creating Android apps, this should be fairly easy with one potentially tricky bit.
- For the layout, you'll need a start and stop button, and a TextView to display the remaining time.
- You'll need two state variables: an integer for the number of seconds remaining, and a boolean to hold the state of the clock. (is it running?)
- Now for the tricky bit. You can't have a loop within the main UI thread counting down the timer, else your app will freeze. You'll need to create a thread that takes 1 away from the remaining seconds variable, and then sleeps for 1 second. You'll also need to make it interruptable when the user presses the Stop and Start buttons. This guide should be a good start for learning about threads.
Those are a few tips that'll help you plan out your app, how you implement that advice is up to you.
|
|
|