Reputation: 123
For some reason, every time the screen orientation is changed my app closes the context menu if it was open. All applications I have seen keep menus open after rotating the screen, but I cannot figure out why my app is closing them.
I am not handling configuration changes on my own and my onCreate method, which I know is called after every orientation change, does not touch menus at all. I would appreciate any insights on this problem.
Upvotes: 2
Views: 2693
Reputation: 22740
The contextMenu disappeared because by default when rotating android calls destroy() and then onCreate() but :
If you don't want Android to go through the normal activity destroy-and-recreate process; instead, you want to handle recreating the views yourself, you can use the android:configChanges attributes on the element in AndroidManifest.xml.
<activity
android:name=".MainActivity"
android:launchMode="singleTask"
android:configChanges="orientation|keyboardHidden">
</activity>
This way contextMenu is not closed when phone rotates, because onCreate() method is not called.
This topic can also be helpful - Activity restart on rotation Android
Upvotes: 1