Use thread to set wait time
when running activity.
For example we want to wait 5
seconds to launch a new class name second. Copy to below findViewById.
Thread background=new Thread(new Runnable()
{
public void run() {
try {
Thread.sleep(5000);
Intent in = new
Intent(MainActivity.this, second.class);
startActivity(in);
}
catch (Throwable t) {
// throw
exception
}
}
});
background.start();
Thread sometime doesn’t run,
wait time out but nothing happen.
Another way is to use Handle.
new
Handler().postDelayed(new Runnable() {
@Override
public void run() {
// run second activity after 5 seconds
Intent in = new
Intent(MainActivity.this, second.class);
startActivity(in);
}
}, 500);
No comments:
Post a Comment