16

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'
Abhishek Kumar
  • 4,532
  • 5
  • 31
  • 53

2 Answers2

21

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.

Abhishek Kumar
  • 4,532
  • 5
  • 31
  • 53
0

Writing installSplashScreen() is enough in koltin class,

 override fun onCreate(savedInstanceState: Bundle?) {
        installSplashScreen()
}
Usman Zafer
  • 1,261
  • 1
  • 10
  • 15