Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Even I'm using MenuItemCompat.setOnActionExpandListener my app crashes with advise to use MenuItemCompat.setOnActionExpandListener [duplicate]

Today Android Studio (set to Stable channel updates) has offered me to download an update to Android Support Repository 46.0.0, so I did it. Then suddenly our app has started to crash each time because of MenuItemCompat.setOnActionExpandListener.

Yes I've should have check release notes yet, but I did not - that's a fact.

Now what's our problem - Even we're using recommended notation MenuItemCompat.setOnActionExpandListener, our app crashed and we're advised to to use MenuItemCompat.setOnActionExpandListener. That's nonsense.

Is there someone who run into the same issue or is it just a matter of our code? Can someone provide an advice how to fix this or how to force to use earlier version of support library? Let's say 25.1.0. Issue seems to be in 26.0.0-alpha1 which is very likely included in Support Repository version 46 (see Release notes for that repository - https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0-alpha1)

Btw. our build.gradle already states fix version for support libs to 25.1.0. It seems new support library somehow forces to use other versions internally when built with gradle.

   compile 'com.android.support:appcompat-v7:25.1.0'
   compile 'com.android.support:design:25.1.0'
   compile 'com.android.support:support-v4:25.1.0'

Thank you very much.

Code

MenuItemCompat.setOnActionExpandListener(menu.findItem(R.id.action_search), new MenuItemCompat.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    ...
                }

Part of StackTrace

    E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.dev, PID: 4835
java.lang.UnsupportedOperationException: This is not supported, use MenuItemCompat.setOnActionExpandListener()
at android.support.v7.view.menu.MenuItemImpl.setOnActionExpandListener(MenuItemImpl.java:745)
at android.support.v4.view.MenuItemCompat.setOnActionExpandListener(MenuItemCompat.java:363)
at com.example.fragments.DevicesFragment.onCreateOptionsMenu(DevicesFragment.java:455)
at android.support.v4.app.Fragment.performCreateOptionsMenu(Fragment.java:2338)
at android.support.v4.app.FragmentManagerImpl.dispatchCreateOptionsMenu(FragmentManager.java:3070)
at android.support.v4.app.FragmentController.dispatchCreateOptionsMenu(FragmentController.java:328)
at android.support.v4.app.FragmentActivity.onCreatePanelMenu(FragmentActivity.java:321)
at android.support.v7.view.WindowCallbackWrapper.onCreatePanelMenu(WindowCallbackWrapper.java:95)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.onCreatePanelMenu(AppCompatDelegateImplBase.java:333)
at android.support.v7.app.AppCompatDelegateImplV9.preparePanel(AppCompatDelegateImplV9.java:1372)
at android.support.v7.app.AppCompatDelegateImplV9.doInvalidatePanelMenu(AppCompatDelegateImplV9.java:1652)
at android.support.v7.app.AppCompatDelegateImplV9$1.run(AppCompatDelegateImplV9.java:134)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)

UPDATE: This seems to be connected to this issue, since I've tried that also and same thing happened to me. I do not want to update to API 26 anyway - Android Support Repo 46.0.0 with Android Studio 2.3

like image 387
T. Tiscalli Avatar asked Oct 29 '22 10:10

T. Tiscalli


1 Answers

It is just a bug in the 26.0.0-alpha1 release. Switch back to 25.3.0 by updating your build.gradle file.

like image 200
ianhanniballake Avatar answered Nov 15 '22 05:11

ianhanniballake