Android countdown timer with pause, resume and finish

Android CountDown Timer Example 2017 no deprecation

Happy to share you Android latest countDown Timer source code with pause resume and finish features include. Android is now working with Kotlin code, Kotlin code is smaller in size than Java. Keep in touch with NextGenEarn Blog for latest Kotlin code updates. CountDown timer does  not mean only count down its have pause and stop feature including listener. Android countdown timer and its source code with full support of android latest version Nougat, Lollipop etc without deprecation.

package Write your package name here;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActity extends AppCompatActivity {

private CountDownTimer countDownTimer;
private boolean timerStart = false;
private Button startB;
public TextView text;
private final long startTime = 20 * 1000;
private final long interval = 1 * 1000;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startB = (Button) this.findViewById(R.id.button);
startB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!timerStart) {
countDownTimer.start();
timerStart = true;
startB.setText(“STOP”);
}
else {
countDownTimer.cancel();
timerStart = false;
startB.setText(“RESTART”);
}
}
});
text = (TextView) this.findViewById(R.id.timer);
countDownTimer = new MyCountDown(startTime, interval);
text.setText(text.getText() + String.valueOf(startTime / 1000));
}

public class MyCountDown extends CountDownTimer {
public MyCountDown(long startTime, long interval) {
super(startTime, interval);
}

@Override
public void onFinish() {
finish();
}

@Override
public void onTick(long millisUntilFinish) {
text.setText(“” + millisUntilFinish / 1000);
}
}
}

activity_main.xml code timer

<?xml version=”1.0″ encoding=”utf-8″ ?>
<RelativeLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:background=”#ffb5bd”>

<TextView
android:id=”@+id/timer”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:layout_centerHorizontal=”true”
android:layout_centerVertical=”true”
android:paddingRight=”10dip”
android:textSize=”50dp” />
<Button
android:id=”@+id/button”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:background=”#ff7f88″
android:layout_alignParentBottom=”true”
android:layout_alignParentLeft=”true”
android:text=”Start” />

</RelativeLayout>

Run the code here how its working – Android video

Searches related to android countdown timer example

how to set timer in android

android countdown timer hours minutes seconds

android countdown timer progress bar

timer in android example

countdown timer android library

android countdown timer github

android countdown timer app

android stopwatch example

Android Speech to Text Source code no deprecation.

Learn more about android count down Timer from android official page.

Add a Comment

Your email address will not be published. Required fields are marked *