Wednesday, April 24, 2013

How to create a thread in an Android App

Below is an example how to create a thread, which will pause your activity for five seconds, then do to another activity.

Within your onCreate method, add the following code.

Thread myTimer = new Thread() {

public void run() {

try {

int timer = 0;

while(timer < 5000) {

sleep(100);
timer = timer + 100;

}
startActivity(new Intent("com.activity.test.clearscreen"));
} catch(Exception e) {

e.printStackTrace();

}

}


};

myTimer.start();


Try my World War II Trivia game by clicking here
Also, download WWII Trivia from the Amazon App Store

No comments:

Post a Comment