Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve method 'installSplashScreen' in 'SplashScreen'

Tags:

android-12

I'm trying to migrate my existing custom Splash screen implementation to Android 12. I have implemented it exact same way as mentioned in the provided link : as mentioned in the provided link

When I write following statement in my SplashActivity, it shows error:

SplashActivity.java

 @Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    SplashScreen.installSplashScreen(this);

    setContentView(R.layout.activity_splash);
 }

the error:

Cannot resolve method 'installSplashScreen' in 'SplashScreen'

for

SplashScreen.installSplashScreen(this);

I have added the following dependency:

implementation 'androidx.core:core-splashscreen:1.0.0-alpha01'
like image 553
Abhishek Kumar Avatar asked Sep 13 '25 16:09

Abhishek Kumar


2 Answers

When I imported the SplashScreen, the default import was:

import android.window.SplashScreen;

And this was the only import available and there was no option to choose from.

After reading the documentation, the package name seems to be the following:

import androidx.core.splashscreen.SplashScreen;

I had to manually change the above import statement. I don't know why I didn't get to choose between the two.

Even after changing the import, SplashScreen was still red(showing error) during compile-time, but I could able to build and run the project without any issue.

like image 191
Abhishek Kumar Avatar answered Sep 15 '25 05:09

Abhishek Kumar


Writing installSplashScreen() is enough in koltin class,

 override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
}
like image 25
Usman Zafer Avatar answered Sep 15 '25 05:09

Usman Zafer