안드로이드 splash screen 중복 문제 해결하기
splash screen 과 launch screen 은 같은 말이다.
앱이 켜질 때 로고 등을 보여주는 화면인데, 이 때 서버에서 정보를 받아올 수 있고 내부적으로 데이터를 로드할 수도 있다.
따로 설정하지 않으면 플러터에서는 흰 화면을 보여준다.
우리는 flutter_native_splash 패키지를 이용해서 굉장히 간단하게 구현할 수 있다.
ios 나 안드로이드 12 버전 이전에서는 잘됐으나 안드로이드 12부터 조금 바뀌었다고 한다.
그래서 안드로이드 12 이상에서는 아래와 같이 두 번 나왔다.
이것을 이해하려면 안드로이드에서 splash screen의 동작원리에 대해 이해할 필요가 있다.
우선 앱이 켜지는 과정을 보면
안드로이드 앱이 실행 -> 플러터가 첫 프레임을 그리는 순서이다.
안드로이드에서 우리가 컨트롤할 수 있는 화면은 두 개인데 용어를 다르게 표현해보겠다.
- 안드로이드 앱이 켜질 때 나오는 launch screen
- flutter가 시작될 때 나오는 splash screen
이 때 flutter가 시작될 때 나오는 splash screen 이란, 안드로이드 앱이 실행되고, 플러터가 첫 프레임을 그리는 사이에 생기는 것이다.
flutter 2.5가 되면서 launch screen만 이용한다고 한다. 대신 플러터가 첫 프레임을 그릴 때 까지 유지시켜주어서 그냥 자연스럽게 된다.
이제는 launch screen만 이용한다니까 splash screen을 없애야 하나만 뜰 것이다.
https://docs.flutter.dev/development/platform-integration/android/splash-screen-migration
Deprecated Splash Screen API Migration
How to migrate from Manifest/Activity defined splash screen.
docs.flutter.dev
FlutterActivity 에 정의되어 있거나 AndroidManifest.xml 에 정의되어 있거나, 둘 다 되어 있을 수 있다.
나의 경우에는 AndroidManifest.xml 파일에 아래부분을 없애니까 됐다.
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
더 세부적인 것은 flutter_native_splash 패키지가 알아서 해준다.
https://pub.dev/packages/flutter_native_splash
flutter_native_splash | Flutter Package
Customize Flutter's default white native splash screen with background color and splash image. Supports dark mode, full screen, and more.
pub.dev
좀 더 자세한 설명은
https://www.youtube.com/watch?v=JVpFNfnuOZM
에서 볼 수 있다.
유튜브 링크 나온 곳 : https://stackoverflow.com/questions/69141338/flutter-v2-5-0-android-splash-screen