java.lang.IllegalStateException: ActionBarImpl can only be used with a compatible window decor layout [closed]
Asked Answered
J

0

28

Within the last days I do see increasing error messages that sound identical. I don't use tablets ActionBar - I'm developing for phones only.

What's the reason for these crashes?

Here's a complete trace:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=8995, result=0, data=null} to activity {xy.yyyy.app.android/xy.yyyy.app.Main}: java.lang.IllegalStateException: ActionBarImpl can only be used with a compatible window decor layout
at android.app.ActivityThread.deliverResults(ActivityThread.java:2818)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:2861)
at android.app.ActivityThread.access$1000(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: ActionBarImpl can only be used with a compatible window decor layout
at com.android.internal.app.ActionBarImpl.init(ActionBarImpl.java:214)
at com.android.internal.app.ActionBarImpl.<init>(ActionBarImpl.java:200)
at android.app.Dialog.show(Dialog.java:255)
at xy.yyyy.app.MyProgressDialog.show(MyProgressDialog.java:33)
at xy.yyyy.app.MyProgressDialog.show(MyProgressDialog.java:23)
at xy.yyyy.app.Main$FetchTask.onPreExecute(Main.java:19)
at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:549)
at android.os.AsyncTask.execute(AsyncTask.java:499)
at xy.yyyy.app.Main.onActivityResult(Main.java:60)
at android.app.Activity.dispatchActivityResult(Activity.java:4581)
at android.app.ActivityThread.deliverResults(ActivityThread.java:2814)
... 11 more

This is a typical AsyncTask that I use from within an activity to start a lengthy task with a ProgressDialog:

private class DeleteTask extends AsyncTask<Void, Void, Boolean> {

  @Override
  protected void onPreExecute () {
    if (!isRunning) {
      progressDialog = MyProgressDialog.show(MyActivity.this,
                                             null,
                                             null,
                                             true,
                                             false);
    }
  }

  @Override
  protected Boolean doInBackground(final Void... strings) {
    Boolean rc = false;

    if (!isRunning) {
      isRunning = true;

      processDelete();
    }

    return rc;
  }

  @Override
  protected void onPostExecute(final Boolean result) {
    if (progressDialog != null) {
      progressDialog.cancel();
    }
    progressDialog = null;

    setResult(RESULT_OK);
    finish();

    isRunning = false;
  }
}

Here's my MyProgressDialog class:

public class MyProgressDialog extends Dialog {

  public MyProgressDialog(final Context context) {
    super(context, R.style.MyProgressDialog);
  }

  public static MyProgressDialog show(final Context context, final CharSequence title, final CharSequence message) {
    return show(context, title, message, false);
  }

  public static MyProgressDialog show(final Context context, final CharSequence title, final CharSequence message, final boolean indeterminate) {
    return show(context, title, message, indeterminate, false, null);
  }

  public static MyProgressDialog show(final Context context, final CharSequence title, final CharSequence message, final boolean indeterminate, final boolean cancelable) {
    return show(context, title, message, indeterminate, cancelable, null);
  }

  public static MyProgressDialog show(final Context context, final CharSequence title, final CharSequence message, final boolean indeterminate, final boolean cancelable, final OnCancelListener onCancelListener) {
    MyProgressDialog dialog = new MyProgressDialog(context);
    dialog.setCancelable(cancelable);
    dialog.setOnCancelListener(onCancelListener);
    dialog.setTitle(title);

    dialog.addContentView(new ProgressBar(context), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    dialog.show();

  return dialog;
  }
}

Many thanks in advance.

EDIT:

Here's the used style:

<style name="MyProgressDialog">
    <item name="android:background">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">false</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:windowTitleStyle">@null</item>
</style>

Here's a screenshot of that ProgressDialog:

enter image description here

SOLUTION:

Had to add this to the style:

parent="@android:style/Theme.Dialog"
Jazzy answered 9/9, 2011 at 10:15 Comment(7)
Thanks to Google reneging on their open-source commitments there's no way to look at ActionBarImpl.java to find out what's going on. First thought: what styles have you got in R.style.MyProgressDialog? Try passing 0 instead of this in the constructor, see if that helps.Carlsen
Thanks for your comment. Did add the style to my question. Unfortunately I don't get that error - even when testing in tablet emulator. I only see that error in crashes that were reported by users using real devices.Jazzy
Heh, that's a very unorthodox dialog, just a progressbar in empty space! I expect the framework is barfing on one those null window attribute values. Suggest you create an alternative version of your <style> without those nulls and put it in res/values-v11/ so it only gets applied to your dialog on Honeycomb or later.Carlsen
That dialog theme style is totally broken. Just to start, you need to have it inherit from one of the base dialog themes.Zimmerman
Thanks for your comment. This did work for all Android releases up to 3.x. What should I do on 3.x to get a rotating cycle without border, background etc. like shown in the picture. Thanks in advance.Jazzy
I could get it to work on all platforms when adding parent="@android:style/Theme.Dialog" to the MyProgressDialog style. I would like to give the bounty reputation to hackbod but this is not possible without an answer. So if you want ...Jazzy
See how to use actionbar in a dialog: #11425520Dimer

© 2022 - 2024 — McMap. All rights reserved.