I am trying to create a countdown timer within the rendering class which will load the main menu once the countdown has finished.
public void startTimer ()
{
new CountDownTimer(30000, 1000) {
public void onTick(long millisUntilFinished)
{
}
public void onFinish()
{
Toast.makeText(Game.context, "TIMER ENDED", Toast.LENGTH_SHORT).show();
// put score into DB
// load up a different screen
}
}.start();
}
I tried using the one shown above, however, when I use it my game closes unexpectedly. It is the timer which is causing the game to close (not the toast).
Anyone know a way I can either implement this or fix the example given above?
(The timer function is placed into 'onSurfaceCreated')
Here is the information from the logCat:
12-10 16:41:45.796: E/AndroidRuntime(5336): FATAL EXCEPTION: GLThread 284 12-10 16:41:45.796: E/AndroidRuntime(5336): Process: com.damienrenner.spacefruitshooter, PID: 5336
12-10 16:41:45.796: E/AndroidRuntime(5336): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()
12-10 16:41:45.796: E/AndroidRuntime(5336): at android.os.Handler.(Handler.java:200)
12-10 16:41:45.796: E/AndroidRuntime(5336): at android.os.Handler.(Handler.java:114)
12-10 16:41:45.796: E/AndroidRuntime(5336): at android.os.CountDownTimer$1.(CountDownTimer.java:109)
12-10 16:41:45.796: E/AndroidRuntime(5336): at android.os.CountDownTimer.(CountDownTimer.java:109)
12-10 16:41:45.796: E/AndroidRuntime(5336): at com.damienrenner.spacefruitshooter.GRenderer$1.(GRenderer.java:274)
12-10 16:41:45.796: E/AndroidRuntime(5336): at com.damienrenner.spacefruitshooter.GRenderer.startTimer(GRenderer.java:274)
12-10 16:41:45.796: E/AndroidRuntime(5336): at com.damienrenner.spacefruitshooter.GRenderer.onSurfaceCreated(GRenderer.java:331)
12-10 16:41:45.796: E/AndroidRuntime(5336): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1501)
12-10 16:41:45.796: E/AndroidRuntime(5336): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)