2

When I run my activity, I get an IllegalStateException: You need to use a Theme.AppCompat theme at random times. I just need to rebuild the project and the activity start on the next run, but after some runs, I get the exception again.

I checked that my application and activities themes inherit from Theme.AppCompat. All my activities extends FragmentActivity

I get the exception on API 22 (Android 5.1.1) and I am running Android Studio 2.0 Beta 5

Edit

I used Android Studio 1.5 and I did not get the error. It seems that on AS 2.0, super in my Activities refers to AppCompatActivity and not to the inherited class FragmentActivity. I can't understand this behavior

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="eu.heyway.heywayandroid">

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar"
        android:name=".HeyWayApplication">
        <activity
            android:name=".login.FacebookLoginActivity"
            android:theme="@style/AppTheme.TriangleBackground">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".configuration.ConfigurationActivity"
            android:label="@string/title_activity_configuration"
            android:theme="@style/AppTheme.TriangleBackground" />
        <activity android:name=".home.HomeActivity"
            android:theme="@style/AppTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

styles.xml

<!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowBackground">@color/colorPrimary</item>
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
    </style>

    <style name="AppTheme.TriangleBackground" parent="AppTheme">
        <item name="android:windowBackground">@drawable/background_full</item>
    </style>

All my activities extends this class :

public class BaseActivity extends FragmentActivity {

    @Override
    protected void attachBaseContext(Context newBase) {
        super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
    }
}

I was wondering if I should report this as a bug or if I am doing something wrong.

Vadim Caen
  • 1,526
  • 11
  • 21
  • 4
    "All my activities extends FragmentActivity" -- either change them to extend `AppCompatActivity`, or stop using `Theme.AppCompat`. `Theme.AppCompat` is for use by `AppCompatActivity`, not `FragmentActivity` or `Activity`. – CommonsWare Feb 22 '16 at 12:05
  • FragmentActivity and Theme.AppCompat -- is causing the issue. I second CommonsWare solution here. – Skynet Feb 22 '16 at 12:05
  • I had the same problem with AppCompatActivity. Actually I changed from AppCompatActivity after seeing the issue – Vadim Caen Feb 22 '16 at 12:16
  • Also, when I change something in the manifest, the error doesn't show on the next launch. I am wondering if the new quick build feature of Android Studio isn't responsible for this. – Vadim Caen Feb 22 '16 at 12:19

1 Answers1

0

In your Manifest you are missing the minSdk and targetSdk entries. Set the min and target sdk versions. Also make sure you included the support libraries. If That didnt worked out, also try with Holo Themes and see if the error comes.

Vishnu
  • 1,516
  • 1
  • 10
  • 15
  • The minSdk and targetSdk are set by gradle. The support libraries are included. If I could avoid to use Holo them it would be great also. – Vadim Caen Feb 22 '16 at 12:49