Search code examples
androidandroid-fragmentsmenuandroid-support-libraryprovider

Android MenuProvider adding menu items out of order when resuming activity w/ fragments?


Has anyone seen this? Feels like a bug in the Android MenuProvider.

  1. Activity A has menu items 1 & 2.
  2. Fragment A in Activity A has menu items 3 & 4. Menu items are in order: 1,2,3,4
  3. startActivity Activity B from Activity A
  4. close Activity B and resume Activity B
  5. The action bar menu now has menu items in order: 3,4,1,2 instead of 1,2,3,4

Lifecycle version 2.6.2 Nav version 2.7.5 AppCompat 1.6.1

I haven't seen any related bug report on b.android.com or question here.


Solution

  • I used the wrong version of addMenuProvider(). Don't use the one with a lifecycleowner and lifecycle state. Just use the single arg addMenuProvider() in your Activity.