Skip to content

Instantly share code, notes, and snippets.

@seal308
Created July 2, 2016 14:38
Show Gist options
  • Select an option

  • Save seal308/57332a9e7f2e89d9f4e01b8c1ffecdc1 to your computer and use it in GitHub Desktop.

Select an option

Save seal308/57332a9e7f2e89d9f4e01b8c1ffecdc1 to your computer and use it in GitHub Desktop.
basic thread, prints time in seconds
public class MainActivity extends Activity {
private Handler myHandler;
boolean gameOn;
long startTime;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startTime = System.currentTimeMillis();
myHandler = new Handler() {
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (gameOn) {
long seconds = ((System.currentTimeMillis() - startTime)) / 1000;
Log.i("info", "seconds = " + seconds);
}
myHandler.sendEmptyMessageDelayed(0, 1000);
}
};
gameOn = true;
myHandler.sendEmptyMessage(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment