简体   繁体   中英

Navigation component and Splash Screen API

I just migrated my splash screen activity to the new splash screen API (( https://developer.android.com/develop/ui/views/launch/splash-screen )).

I am also using the Navigation component to move from the Main activity to a secondary activity.

So far I am able to open the main activity. This is the onCreate() method within the main activity.

override fun onCreate(savedInstanceState: Bundle?) {
    installSplashScreen()
    super.onCreate(savedInstanceState)
    ...

within the fragment of the main activity I call

findNavController().navigate(directions)

to navigate to the second activity and the app crashes with:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

If I call installSplashScreen() in the second activity, it works, but on some devices I get:

Unable to start activity ComponentInfo{xxx/SecondActivity}: androidx.fragment.app.o$d: Unable to instantiate fragment ab.q: could not find Fragment constructor

Thanks.

Calling installSplashScreen() in tje second activity is correct. The problem with other was due to the fact that I had a nested fragment with arguments constructor. I refactored the fragment to no args constructor by using bundle to set the argument and it all works now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM