本文共 1611 字,大约阅读时间需要 5 分钟。
I am using deep link, launchMode="singleTask". If there is an instance of my activity everything works fine: only onNewIntent is called. But if there is no instance, firstly onCreate is called, then onNewIntent and again onCreate. That is why, the screen flickers. What is the problem? I removed all code, and only logged the events. But the same behavior is observed.
android:name="uz.avtobank.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:launchMode="singleTask"
android:screenOrientation="nosensor"
android:theme="@style/SplashActivityTheme"
android:windowSoftInputMode="adjustResize|stateHidden">
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setTheme(R.style.AppTheme)
setContentView(R.layout.activity_main)
val host = NavHostFragment.create(R.navigation.nav_graph_main)
supportFragmentManager.beginTransaction()
.replace(R.id.container, host)
.setPrimaryNavigationFragment(host)
.commit()
logMessage("onCreate ${intent.action}")
}
@SuppressLint("DefaultLocale")
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
logMessage("onNewIntent ${intent.action}")
handleIntent(intent)
}
private fun handleIntent(intent: Intent) {
if (intent.action != Intent.ACTION_VIEW)
return
try {
findNavController(R.id.container).handleDeepLink(intent)
} catch (e: IllegalStateException) {
} catch (e: IllegalArgumentException) {
}
setIntent(intent)
}
The following appears on the log:
There is instance: onNewIntent
There is no instance: onCreate, onNewIntent, onCreate
The same happens evene if I remove handleIntent method.
转载地址:http://lejdv.baihongyu.com/