'How to switch activities without animation?
I read a lot of similar questions but no one solution helped me. Now, I have the next code of LauncherActivity:
class LauncherActivity : AppCompatActivity(), DIAware {
override val di by closestDI()
private val getAccount: GetAccountUseCase by instance()
override fun onCreate(savedInstanceState: Bundle?) {
installSplashScreen()
val activityClass = if (this.getAccount() == null) {
LoginActivity::class.java
} else {
MainActivity::class.java
}
val intent = Intent(this, activityClass)
.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
overridePendingTransition(0,0)
finish()
super.onCreate(savedInstanceState)
}
}
However, it works as long as I don't call finish(). If I call finish() animations begin to show again.
Where can the problem be? I have retried all possible combinations of these lines and flags, it doesn't work with finish().
P.S. I know that I can use styles to turn off animations but it doesn't suit for my purposes, I need a solution to achieve it programmatically.
Solution 1:[1]
Themes.xml
<style name="noAnimation" parent="android:Theme">
<item name="android:windowAnimationStyle">@null</item>
</style>
AndroidManifest.xml
<activity android:name=".LauncherActivity"
android:theme="@style/noAnimTheme">
</activity>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ă–mer Seyfettin Yavuzyi?it |
