Kotlin example:
private val SPLASH_DELAY: Long = 1000
internal val mRunnable: Runnable = Runnable {
if (!isFinishing) {
val intent = Intent(applicationContext, HomeActivity::class.java)
startActivity(intent)
overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
finish()
}
}
private fun navigateToHomeScreen() {
//Initialize the Handler
mDelayHandler = Handler()
//Navigate with delay
mDelayHandler!!.postDelayed(mRunnable, SPLASH_DELAY)
}
public override fun onDestroy() {
if (mDelayHandler != null) {
mDelayHandler!!.removeCallbacks(mRunnable)
}
super.onDestroy()
}
put animations in anim folder:
slide_in.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="100%p"
android:toXDelta="0%p">
</translate>
slide_out.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_longAnimTime"
android:fromXDelta="0%p"
android:toXDelta="-100%p">
</translate>
USAGE
navigateToHomeScreen();