How I resolved the “You need to use a Theme.AppCompat theme (or descendant) with this activity” Issue.
Android 12 issue...
How I resolved the “You need to use a Theme.AppCompat theme (or descendant) with this activity” Issue.
Android 12 issue...
Step:-1 Add this theme.
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Android_12_Splash_Demo" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="windowSplashScreenBackground">@color/white</item>
<item name="windowSplashScreenAnimatedIcon">@drawable/ic_camera_edit</item>
<item name="windowSplashScreenAnimationDuration">300</item>
<item name="postSplashScreenTheme">@style/Theme.Android_12_Splash_Demo</item>
<item name="android:navigationBarColor">@color/black</item>
<!-- This is used for status bar hide and show-->
<item name="android:windowLightStatusBar">false</item>
<!-- This use bottom brand image -->
<item name="android:windowSplashScreenBrandingImage" tools:targetApi="s">@drawable/ic_camera_edit</item>
</style>
</resources>
Step:- 2 assign this theme to application in manifest
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Android_12_Splash_Demo">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".DashboardActivity"
android:exported="false" />
<activity
android:name=".LoginActivity"
android:exported="false" />
</application>
I've faced the same error while migrating to the new SplashScreen API. For me, it was helpful to call installSplashScreen() in the starting activity before calling super.onCreate().
Documentation: https://developer.android.com/guide/topics/ui/splash-screen/migrate#migrate_your_splash_screen_implementation