Saving the context menu after screen rotation

I have an activity that runs onCreate on it:

registerForContextMenu (theView);

and in onCreateContextMenu:

super.onCreateContextMenu(menu, v, menuInfo);
menu.add(blablabla);

This works fine, but the problem is that the context menu disappears when the screen rotates. How to fix it?

Thanks for reading!

+3
source share
3 answers

Here's the solution:

The context menu has disappeared because by default when you rotate android calls destroy () and then onCreate () , but :

, Android ; , android: configChanges AndroidManifest.xml.

<activity
    android:name=".SmsPopupActivity"
    android:theme="@android:style/Theme.Dialog"
    android:launchMode="singleTask"
    android:configChanges="orientation|keyboardHidden"
    android:taskAffinity="net.everythingandroid.smspopup.popup">
</activity>

, my contextMenu , , onCreate() .

. :

+5

Android:

Activity , RetainNonConfigurationInstance(). - Android , , . [...] :

@Override public Object
onRetainNonConfigurationInstance() {
final LoadedPhoto[] list = new LoadedPhoto[numberOfPhotos];
keepPhotos(list);
return list; }

, onCreate(), , , - getLastNonConfigurationInstance(). Photostream, , :

http://android-developers.blogspot.com/2009/02/faster-screen-orientation-change.html?utm_source=eddie

+2

Maybe I'm wrong, but due to the fact that I know you cannot save it, however (this is the part where I can be wrong), you can open the menu dynamically after the rotation. Giving the illusion of perseverance.

0
source

Source: https://habr.com/ru/post/1721747/


All Articles