I am developing an android application. In this application, I want to transition from one activity to another activity automatically after 4 seconds. I don't know how to do this without a button.
This is how you can proceed:
int timeout = 4000; // make the activity visible for 4 seconds
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
finish();
Intent homepage = new Intent(Activity1.this, Activity2.class);
startActivity(homepage);
}
}, timeout);
Add the code in your oncreate()
@Override
protected void onCreate(Bundle savedInstanceState) {
Handler handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(MainActivity.this, AnotherActivity.class);
startActivity(intent);
}
},4000);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With