Android: Redirect to another Activity after delay
To make a delayed transition use Handler
class's postDelayed(Runnable r, long delayMillis)
method, for example:
Java
Runnable r = new Runnable() {
@Override
public void run() {
// if you are redirecting from a fragment then use getActivity() as the context.
startActivity(new Intent(CurrentActivity.this, TargetActivity.class));
}
};
Handler h = new Handler();
// The Runnable will be executed after the given delay time
h.postDelayed(r, 1500); // will be delayed for 1.5 seconds
Kotlin with Anko
val someThread = Runnable {
startActivity(intentFor<TargetActivity>())
}
Handler().postDelayed(someThread, 1500)
Simply call a new activity through intent:
Intent i = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(i);
finish();
Check this:-
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i=new Intent(CurrentActivity.this,Next.class);
startActivity(i);
}
}, 3000);