|
|
CountDownTimer(bignum, 1000) is instanced to accept parameter bignum = Long.MAX_VALUE. bignum is decremented every second. it will take approximately 5.849x10^11 years to reach zero at which time a new Android will likely have emerged.
package com.brainyideas.dev.poc.tltd;
import android.app.Activity;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;
public class TimeDisplay extends Activity {
TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tv = (TextView) findViewById(R.id.textView1);
long bignum;
// get the largest possible long value and decrement it every second
// it will take approximately 5.849x10^11 years to reach zero at which time a new Android will likely have emerged
bignum = Long.MAX_VALUE;
// this is same as,
//bignum = (long) Math.pow(2,64) - 1;
new CountDownTimer(bignum, 1000) {
public void onTick(long millisUntilFinished) {
tv.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
tv.setText("done!");
}
}.start();
}
}<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:text="@string/startvalue" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>