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

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activitylifecycletest/com.example.activitylifecycletest.DialogActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThreadH.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInitMethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:555)
        at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:518)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:466)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at com.example.activitylifecycletest.DialogActivity.onCreate(DialogActivity.java:11)
        at android.app.Activity.performCreate(Activity.java:6285)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
        at android.app.ActivityThread.-wrap11(ActivityThread.java)
        at android.app.ActivityThreadH.handleMessage(ActivityThread.java:1344)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:148)
        at android.app.ActivityThread.main(ActivityThread.java:5417)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:103)

The above error codes can be easily located and solved in Android Studio. There are two solutions:

  1. Find the activity that reported the error (the above error log is com.example.activitylifecycletest.DialogActivity) and modify the theme theme in AndroidManifest.xml to make it refer to theme.appcompat.***. ps: If it is invalid, you can modify the theme of Application, Also referenced in the.appcompat.
  2. Modify the inheritance relationship of DialogActivity so that it does not inherit AppCompatActivity, just inherit Activity
    If you encounter this problem when decompiling, then things are different. When I encountered this problem for the first time, I found that there was no problem with the inheritance relationship of Activity and the theme index of theme. So what is the problem?
    After pondering for a long time, I found this code in the AppCompatDelegateImpl class:
if (!a.hasValue(R.styleable.AppCompatTheme_windowActionBar)) {
    a. recycle();
    throw new IllegalStateException(
    "You need to use a Theme.AppCompat theme (or descendant) with this activity.");
    }

R.styleable.AppCompatTheme_windowActionBar
This resource index doesn’t seem to be found. After searching, I found that I couldn’t find it. I copied all the resource files generated by decompilation, and the resource of declare-styleable.xml required by R.styleable.AppCompatTheme_windowActionBar was converted into The attr tag in attrs.xml.
For example: AppCompatTheme’s styleable is defined as:

<declare-styleable name="AppCompatTheme">
        <eat-comment/>
        <attr format="boolean" name="windowActionBar"/>
        <attr format="boolean" name="windowNoTitle"/>
        <attr format="boolean" name="windowActionBarOverlay"/>
        <attr format="boolean" name="windowActionModeOverlay"/>
        <attr format="dimension|fraction" name="windowFixedWidthMajor"/>
        <attr format="dimension|fraction" name="windowFixedHeightMinor"/>
        <attr format="dimension|fraction" name="windowFixedWidthMinor"/>
        <attr format="dimension|fraction" name="windowFixedHeightMajor"/>
        <attr format="dimension|fraction" name="windowMinWidthMajor"/>
        <attr format="dimension|fraction" name="windowMinWidthMinor"/>
        <attr name="android:windowIsFloating"/>
        <attr name="android:windowAnimationStyle"/>
        <eat-comment/>
        <attr format="reference" name="actionBarTabStyle"/>
        <attr format="reference" name="actionBarTabBarStyle"/>
        <attr format="reference" name="actionBarTabTextStyle"/>
        <attr format="reference" name="actionOverflowButtonStyle"/>
        <attr format="reference" name="actionOverflowMenuStyle"/>
        <attr format="reference" name="actionBarPopupTheme"/>
        <attr format="reference" name="actionBarStyle"/>
        <attr format="reference" name="actionBarSplitStyle"/>
        <attr format="reference" name="actionBarTheme"/>
        <attr format="reference" name="actionBarWidgetTheme"/>
        <attr format="dimension" name="actionBarSize">
            <enum name="wrap_content" value="0"/>
        </attr>
        <attr format="reference" name="actionBarDivider"/>
        <attr format="reference" name="actionBarItemBackground"/>
        <attr format="reference" name="actionMenuTextAppearance"/>
        <attr format="color|reference" name="actionMenuTextColor"/>
        <eat-comment/>
        <attr format="reference" name="actionModeStyle"/>
        <attr format="reference" name="actionModeCloseButtonStyle"/>
        <attr format="reference" name="actionModeBackground"/>
        <attr format="reference" name="actionModeSplitBackground"/>
        <attr format="reference" name="actionModeCloseDrawable"/>
        <attr format="reference" name="actionModeCutDrawable"/>
        <attr format="reference" name="actionModeCopyDrawable"/>
        <attr format="reference" name="actionModePasteDrawable"/>
        <attr format="reference" name="actionModeSelectAllDrawable"/>
        <attr format="reference" name="actionModeShareDrawable"/>
        <attr format="reference" name="actionModeFindDrawable"/>
        <attr format="reference" name="actionModeWebSearchDrawable"/>
        <eat-comment/>
        <attr format="reference" name="textAppearanceLargePopupMenu"/>
        <attr format="reference" name="textAppearanceSmallPopupMenu"/>
        <attr format="reference" name="textAppearancePopupMenuHeader"/>
        <attr format="reference" name="dialogTheme"/>
        <attr format="dimension" name="dialogPreferredPadding"/>
        <attr format="reference" name="listDividerAlertDialog"/>
        <attr format="dimension" name="dialogCornerRadius"/>
        <attr format="reference" name="actionDropDownStyle"/>
        <attr format="dimension" name="dropdownListPreferredItemHeight"/>
        <attr format="reference" name="spinnerDropDownItemStyle"/>
        <attr format="reference" name="homeAsUpIndicator"/>
        <attr format="reference" name="buttonBarStyle"/>
        <attr format="reference" name="buttonBarButtonStyle"/>
        <attr format="reference" name="selectableItemBackground"/>
        <attr format="reference" name="selectableItemBackgroundBorderless"/>
        <attr format="reference" name="borderlessButtonStyle"/>
        <attr format="reference" name="dividerVertical"/>
        <attr format="reference" name="dividerHorizontal"/>
        <attr format="reference" name="activityChooserViewStyle"/>
        <attr format="reference" name="toolbarStyle"/>
        <attr format="reference" name="toolbarNavigationButtonStyle"/>
        <attr format="reference" name="popupMenuStyle"/>
        <attr format="reference" name="popupWindowStyle"/>
        <attr format="reference|color" name="editTextColor"/>
        <attr format="reference" name="editTextBackground"/>
        <attr format="reference" name="imageButtonStyle"/>
        <eat-comment/>
        <attr format="reference" name="textAppearanceSearchResultTitle"/>
        <attr format="reference" name="textAppearanceSearchResultSubtitle"/>
        <attr format="reference|color" name="textColorSearchUrl"/>
        <attr format="reference" name="searchViewStyle"/>
        <eat-comment/>
        <attr format="dimension" name="listPreferredItemHeight"/>
        <attr format="dimension" name="listPreferredItemHeightSmall"/>
        <attr format="dimension" name="listPreferredItemHeightLarge"/>
        <attr format="dimension" name="listPreferredItemPaddingLeft"/>
        <attr format="dimension" name="listPreferredItemPaddingRight"/>
        <attr format="dimension" name="listPreferredItemPaddingStart"/>
        <attr format="dimension" name="listPreferredItemPaddingEnd"/>
        <attr format="reference" name="dropDownListViewStyle"/>
        <attr format="reference" name="listPopupWindowStyle"/>
        <attr format="reference" name="textAppearanceListItem"/>
        <attr format="reference" name="textAppearanceListItemSecondary"/>
        <attr format="reference" name="textAppearanceListItemSmall"/>
        <eat-comment/>
        <attr format="reference" name="panelBackground"/>
        <attr format="dimension" name="panelMenuListWidth"/>
        <attr format="reference" name="panelMenuListTheme"/>
        <attr format="reference" name="listChoiceBackgroundIndicator"/>
        <eat-comment/>
        <attr format="color" name="colorPrimary"/>
        <attr format="color" name="colorPrimaryDark"/>
        <attr format="color" name="colorAccent"/>
        <attr format="color" name="colorControlNormal"/>
        <attr format="color" name="colorControlActivated"/>
        <attr format="color" name="colorControlHighlight"/>
        <attr format="color" name="colorButtonNormal"/>
        <attr format="color" name="colorSwitchThumbNormal"/>
        <attr format="reference" name="controlBackground"/>
        <attr format="reference" name="alertDialogStyle"/>
        <attr format="reference" name="alertDialogButtonGroupStyle"/>
        <attr format="boolean" name="alertDialogCenterButtons"/>
        <attr format="reference" name="alertDialogTheme"/>
        <attr format="reference|color" name="textColorAlertDialogListItem"/>
        <attr format="reference" name="buttonBarPositiveButtonStyle"/>
        <attr format="reference" name="buttonBarNegativeButtonStyle"/>
        <attr format="reference" name="buttonBarNeutralButtonStyle"/>
        <eat-comment/>
        <attr format="reference" name="autoCompleteTextViewStyle"/>
        <attr format="reference" name="buttonStyle"/>
        <attr format="reference" name="buttonStyleSmall"/>
        <attr format="reference" name="checkboxStyle"/>
        <attr format="reference" name="checkedTextViewStyle"/>
        <attr format="reference" name="editTextStyle"/>
        <attr format="reference" name="radioButtonStyle"/>
        <attr format="reference" name="ratingBarStyle"/>
        <attr format="reference" name="ratingBarStyleIndicator"/>
        <attr format="reference" name="ratingBarStyleSmall"/>
        <attr format="reference" name="seekBarStyle"/>
        <attr format="reference" name="spinnerStyle"/>
        <attr format="reference" name="switchStyle"/>
        <attr format="reference" name="listMenuViewStyle"/>
        <attr format="reference" name="tooltipFrameBackground"/>
        <attr format="reference|color" name="tooltipForegroundColor"/>
        <attr format="reference|color" name="colorError"/>
        <attr format="string" name="viewInflaterClass"/>
        <eat-comment/>
        <attr format="reference" name="listChoiceIndicatorMultipleAnimated"/>
        <attr format="reference" name="listChoiceIndicatorSingleAnimated"/>
    </declare-styleable>

But what I got was the decompiled resource identifier, the declare-styleable tag was removed, the name attribute could not be found, only attr, then R.styleable.AppCompatTheme_windowActionBar must not be found, so an error was reported. .

Solution

It is to get declare-styleables.xml again, delete attr defined in declare-styleables.xml in attrs, and the problem is solved~