0

In my app, I have a ListView with List item, long press will display ContextMenu. Here, I need to do Orientation change. So that, I followed like without adding onConfigChanges attribute in Manifest file manually i have handle that Orientation change using onRetainNonConfigurationChanges() method.

My issue is after item long press it will show the ContextMenu on that time if change the Orientation it's getting closed.

Please refer any solution other than adding android:onConfigChnage="orienation" in Manifest.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Srinivasan
  • 4,481
  • 3
  • 28
  • 36

2 Answers2

0

Actually this issue is occurring due to the restarting of Activity. When the screen Orientation changes, android system restart the current Activity.

See here and here the same issue. May be you get some idea.

Community
  • 1
  • 1
Rajesh Rajaram
  • 3,271
  • 4
  • 29
  • 48
  • Yes you are right dude. i know about this already but only problem is i have retained all the values and i have used two different layout for that same activity but i can't able to avoid the floating Context menu closing. – Srinivasan Nov 09 '12 at 09:31
-1

that is the normal behaviour. ContextMenus just like alert dialogs are part of the activity life cycle and as such, they get killed with the activity.

the solution is override protected void onSaveInstanceState(Bundle outState) and save the current state of your activity and get the savedInstanceState back during your activity onCreate

Budius
  • 39,391
  • 16
  • 102
  • 144
  • Hmm yea...I know here i am using another method like onRetainNonConigurationChanges() method to retain the values.But my issue is That floating Context Menu is closing on the Orientation Changing time.Here what i need to do is i need to keep show the Context Menu even though orientation changing time.For that as you said like dialog means i need to check the Context Menu is showing or not and then i need to show it again explicitly in onResume() method after activity created.For these thing i need your guide lines. – Srinivasan Nov 09 '12 at 09:41
  • you just explain the solution yourself. I won't write the code for you. Whenever you're opening the menu, you set a flag, whenever closing you reset the flag. You pass this flag over during orientation changes and onResume you check its value to open again or not the menu. – Budius Nov 09 '12 at 09:45
  • Dude...Here you can't check whether the context menu is opened or not? – Srinivasan Nov 09 '12 at 13:46
  • but you can override the `onContextItemSelected` and `onContextMenuClosed` and set/reset some boolean or integer to know that it is opened. – Budius Nov 09 '12 at 13:48