I tried all solutions from this link but none of them works for me
Process: org.dmfs.tasks, PID: 12137 java.lang.RuntimeException: Unable
to start activity
ComponentInfo{org.dmfs.tasks/org.dmfs.tasks.Main.TimerActivity}:
java.lang.IllegalStateException: This Activity already has an action
bar supplied by the window decor. Do not request
Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in
your theme to use a Toolbar instead.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) Caused by: java.lang.IllegalStateException: This Activity already has
an action bar supplied by the window decor. Do not request
Window.FEATURE_SUPPORT_ACTION_BAR and set windowActionBar to false in
your theme to use a Toolbar instead.
at androidx.appcompat.app.AppCompatDelegateImpl.setSupportActionBar(AppCompatDelegateImpl.java:408)
at androidx.appcompat.app.AppCompatActivity.setSupportActionBar(AppCompatActivity.java:150)
at org.dmfs.tasks.Main.TimerActivity.onCreate(TimerActivity.java:173)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
my theme in styles.xml:
<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar">
<item name="colorPrimary">@color/white</item>
<item name="colorPrimaryVariant">@color/white</item>
<item name="colorOnPrimary">#000</item>
<item name="colorSecondary">@color/teal200</item>
<item name="colorSecondaryVariant">@color/teal300</item>
<item name="colorOnSecondary">@color/white</item>
<item name="android:colorBackground">@color/gray1000</item>
<item name="colorOnBackground">@color/white</item>
<item name="colorSurface">@color/black</item>
<item name="colorOnSurface">@color/white</item>
<item name="colorPrimaryDark">@color/white</item>
<item name="android:windowBackground">@color/black</item>
<item name="android:textColorPrimary">@android:color/black</item>
<item name="appBarColor">@color/black</item>
<item name="cardViewColor">@color/black</item>
<item name="alertDialogColor">@color/gray1000</item>
<item name="viewInflaterClass">androidx.appcompat.app.AppCompatViewInflater</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeCloseDrawable">@drawable/ic_clear</item>
<item name="actionModeStyle">@style/ActionModeStyle</item>
<item name="alertDialogTheme">@style/DialogTheme</item>
<item name="palette">@array/lightPalette</item>
<item name="fontFamily">@font/app_font</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
theme Activity in my manifest:
<activity
android:name="org.dmfs.tasks.Main.TimerActivity"
android:showOnLockScreen="true"
android:launchMode="singleTask"
android:theme="@style/AppTheme">
Code from the Activity:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EventBus.getDefault().register(this);
}
ThemeHelper.setTheme(this);
ActivityMain3Binding binding = DataBindingUtil.setContentView(this, R.layout.activity_main3);
mBlackCover = binding.blackCover;
mToolbar = binding.bar;
mTimeLabel = binding.timeLabel;
mTutorialDot = binding.tutorialDot;
mBoundsView = binding.main;
mViewModel = ViewModelProviders.of(this).get(TimerActivityViewModel.class);
setupTimeLabelEvents();
setSupportActionBar(mToolbar);
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(null);
}
the error produces by this line : setSupportActionBar(mToolbar); i want to use a toolbar from activity_main with the ID "bar" instead of the default action bar.How can i solve this?
note: I didn't have this error, it was produced suddenly when I updated android studio canary to 3.6