Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old November 29th, 2011, 02:49 AM   #1 (permalink)
New Member
 
mineko's Avatar
 
Join Date: Nov 2011
Location: philippines
Posts: 7
 
Device(s): android 3.2
Thanks: 1
Thanked 0 Times in 0 Posts
Laugh Android: How to pause and resume a Count Down Timer?

I have developed a Count Down Timer and I am not sure how to pause and resume the timer as the textview for the timer is being clicked. Click to start then click again to pause and to resume, click ag]ain the timer's text view.

This is my code:

Timer = (TextView)this.findViewById(R.id.time); //TIMER
Timer.setOnClickListener(TimerClickListener);
counter = new MyCount(600000, 1000);
}//end of create

private OnClickListener TimerClickListener = new OnClickListener() {
public void onClick(View v) {
updateTimeTask(); }

private void updateTimeTask() {
if (decision==0){
counter.start();
decision=1;}
else if(decision==2){
counter.onResume1();
decision=1; }
else{
counter.onPause1();
decision=2; }//end if
}; };

class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}//MyCount
public void onResume1(){
onResume(); }
public void onPause1() {
onPause();}
public void onFinish() {
Timer.setText("00:00");
p1++;
if (p1<=4){
TextView PScore = (TextView) findViewById(R.id.pscore);
PScore.setText(p1 + "");
}//end if
}//finish
public void onTick(long millisUntilFinished) {
Integer milisec = new Integer(new Double(millisUntilFinished).intValue());
Integer cd_secs = milisec / 1000;

Integer minutes = (cd_secs % 3600) / 60;
Integer seconds = (cd_secs % 3600) % 60;

Timer.setText(String.format("%02d", minutes) + ":"
+ String.format("%02d", seconds));
///long timeLeft = millisUntilFinished / 1000;
/}//on tick
}//class MyCount

protected void onResume() {
super.onResume();
//handler.removeCallbacks(updateTimeTask);
//handler.postDelayed(updateTimeTask, 1000);
}//onResume

@Override
protected void onPause() {
super.onPause();
//do stuff
}//onPause
Any help would be appreciated. thanks!


If savedInstanceState is should I use to store the timer value for pause and resume it again, how would I do it? Sorry I am only new in android programming

Any help would be appreciated. thanks!

mineko is offline  
Reply With Quote
Sponsors
Reply

Bookmarks

Tags
android, java, java on android


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:17 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo