How to automatic intent to other activity like from SplashActivity to other Activity with timer using Kotlin?
Asked
Active
Viewed 205 times
3 Answers
1
You can use handler to have deferred work queued.
android.os.Handler(Looper.getMainLooper()).postDelayed({
// This will execute after 5 seconds(5000 milliseconds)
// val intent = Intent(context, Destination::class.java)
// startActivity(intent)
// finish()
}, 5000)

Sahitya Pasnoor
- 597
- 5
- 11
0
Use handler with delay, after delay navigate to other Activity and call finish() in your SplashActivity.

Vahan
- 3,016
- 3
- 27
- 43
0
Refer to this sample. It will help you.
public class SplashScreen extends AppCompatActivity {
private final Handler handler = new Handler();
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
final WindowInsetsController insetsController = getWindow().getInsetsController();
if (insetsController != null) {
insetsController.hide(WindowInsets.Type.statusBars());
}
} else {
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
);
}
handler.postDelayed(() -> {
startActivity(new Intent(SplashScreen.this, TermsScreen.class));
finish();
}, 1000);
}
}

Shenal Akalanka
- 54
- 7