Created
July 7, 2017 05:42
-
-
Save bgloh/4c03442550522429d42e21edc1e2a669 to your computer and use it in GitHub Desktop.
Java periodic timer handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.brian.myapplication_timer_handler; | |
import android.os.Handler; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
public class MainActivity extends AppCompatActivity { | |
Handler handler = new Handler(); | |
int timeRemaining = 100000; // 100 second | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
handler.post(runnable); | |
} | |
private Runnable runnable = new Runnable() { | |
@Override | |
public void run() { | |
// repeat unttil time remaining is greater than zero. | |
timeRemaining = timeRemaining - 5000; // | |
if (timeRemaining > 0) | |
handler.postDelayed(runnable,5000); | |
Log.d("bgloh", "handlier is working"); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment