-1

I looked at other SO posts and configured accordingly. But I still see this issue on some Android devices (4.3.1). It works 75% of time.

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

What is wrong with code below?

BaseActivity extends android.support.v7.appAppCompatActivity



<application
    android:allowBackup="true"
    android:theme="@style/AppTheme" >

All activities (crashed acitivity as well) use AppTheme from application tag. One activity uses:

    <activity
        android:name=".Activities.EntryActivity"
        android:noHistory="true"
        android:theme="@style/SplashTheme" >

I don't have any other style.xml.

<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

From Android:

<style name="Theme.AppCompat.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

java.lang.RuntimeException: Unable to start activity ComponentInfo{Activities.MyAcitivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 2 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 3 at android.app.ActivityThread.access$600(ActivityThread.java:141) 4 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 5 at android.os.Handler.dispatchMessage(Handler.java:99) 6 at android.os.Looper.loop(Looper.java:137) 7 at android.app.ActivityThread.main(ActivityThread.java:5103) 8 at java.lang.reflect.Method.invokeNative(Native Method) 9 at java.lang.reflect.Method.invoke(Method.java:525) 10 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 11 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 12 at com.android.internal.os.ZygoteInit.main(Native Method) 13 at dalvik.system.NativeStart.main(Native Method) 14 Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 15 at android.support.v7.app.AppCompatDelegateImplV7.i(SourceFile:340) 16 at android.support.v7.app.AppCompatDelegateImplV7.h(SourceFile:309) 17 at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:273) 18 at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:136) 19 at .Commons.BaseActivity.onCreate(SourceFile:236) 20 at .MyActivity.onCreate(SourceFile:24) 21 at android.app.Activity.performCreate(Activity.java:5133) 22 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 23 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 24 ... 12 more 25 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 26 at android.support.v7.app.AppCompatDelegateImplV7.i(SourceFile:340) 27 at android.support.v7.app.AppCompatDelegateImplV7.h(SourceFile:309) 28 at android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:273) 29 at android.support.v7.app.AppCompatActivity.setContentView(SourceFile:136) 30 at Activities.Commons.BaseActivity.onCreate(SourceFile:236) 31 at Activities.Accounts.AppLaunchActivity.onCreate(SourceFile:24) 32 at android.app.Activity.performCreate(Activity.java:5133) 33 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 34 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175) 35 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 36 at android.app.ActivityThread.access$600(ActivityThread.java:141) 37 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256) 38 at android.os.Handler.dispatchMessage(Handler.java:99) 39 at android.os.Looper.loop(Looper.java:137) 40 at android.app.ActivityThread.main(ActivityThread.java:5103) 41 at java.lang.reflect.Method.invokeNative(Native Method) 42 at java.lang.reflect.Method.invoke(Method.java:525) 43 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 44 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 45 at com.android.internal.os.ZygoteInit.main(Native Method) 46 at dalvik.system.NativeStart.main(Native Method)

GJain
  • 5,025
  • 6
  • 48
  • 82

1 Answers1

0

try this:

in res/values/styles.xml:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

Now in your manifest:

<application
    android:theme="@style/AppTheme">   //base Application theme
    <activity
        android:name=".Activities.EntryActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">   //Activity Theme
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62
  • I don't need Theme.AppCompat.Light.DarkActionBar. Then why do I need to add it to style.xml? – GJain Feb 16 '17 at 19:01
  • it really doesn't matter...you are not using the `DarkActionBar` if u set the theme to be `AppTheme.NoActionBar`..if u don;t want it u can use `android:theme="@style/Theme.AppCompat.Light"` as ur applicaiton theme..see this: http://stackoverflow.com/questions/39604889/how-to-fix-you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-a – rafsanahmad007 Feb 16 '17 at 19:10