On Nov 2, 11:16 pm, Macarse <[email protected]> wrote:
> On Oct 28, 5:54 pm, skataben <[email protected]> wrote:
>
>
>
> > My app creates a simple ListActivity. I want the ListView's context
> > menu to stay on the screen when it rotates, so I cache the selected
> > item's position. When the activity resumes I call openContextMenu
> > (getListView()) and use the cached item's position to retrieve the
> > ListView item's info. The info is successfully restored (as observed
> > in the debugger), but the app crashes somewhere after
> > onCreateContextMenu() is finished executing.
>
> > The debugger gives me the following info, but I don't know exactly
> > what it means:
>
> > 10-28 15:29:50.548: INFO/WindowManager(61): onOrientationChanged,
> > rotation changed to 0
> > 10-28 15:29:50.808: WARN/WindowManager(61): Requested window null does
> > not exist
> > 10-28 15:29:50.808: WARN/WindowManager(61): java.lang.RuntimeException
> > 10-28 15:29:50.808: WARN/WindowManager(61):     at
> > com.android.server.WindowManagerService.windowForClientLocked
> > (WindowManagerService.java:7377)
> > 10-28 15:29:50.808: WARN/WindowManager(61):     at
> > com.android.server.WindowManagerService.addWindow
> > (WindowManagerService.java:1145)
> > 10-28 15:29:50.808: WARN/WindowManager(61):     at
> > com.android.server.WindowManagerService$Session.add
> > (WindowManagerService.java:5267)
> > 10-28 15:29:50.808: WARN/WindowManager(61):     at
> > android.view.IWindowSession$Stub.onTransact(IWindowSession.java:74)
> > 10-28 15:29:50.808: WARN/WindowManager(61):     at
> > com.android.server.WindowManagerService$Session.onTransact
> > (WindowManagerService.java:5240)
> > 10-28 15:29:50.808: WARN/WindowManager(61):     at
> > android.os.Binder.execTransact(Binder.java:287)
> > 10-28 15:29:50.808: WARN/WindowManager(61):     at
> > dalvik.system.NativeStart.run(Native Method)
> > 10-28 15:29:50.808: WARN/WindowManager(61): Attempted to add window
> > with token that is not a window: null.  Aborting.
>
> > What am I doing wrong?
>
> > public class LoginActivity extends ListActivity implements Runnable {
>
> >         private int mContextMenuPosition = -1;
>
> >         @Override
> >         public void onCreate(Bundle icicle) {
> >         ...
> >         registerForContextMenu(getListView());
> >         ...
> >         }
>
> >         @Override
> >         public void onCreateContextMenu(ContextMenumenu, View v,
> > ContextMenuInfo menuInfo) {
> >                 try {
> >                         int position;
> >                         super.onCreateContextMenu(menu, v, menuInfo);
> >                         AdapterContextMenuInfo info = 
> > (AdapterContextMenuInfo)
> > menuInfo;
> >                         position = (info == null) ? mContextMenuPosition :
> > info.position;
> >                         ....more stuff
> >                 }
> >                 catch ( Exception ex ) { // exception not caught, so the 
> > problem is
> > elsewhere
> >                         toastException( ex );
> >                         logException(ex);
> >                 }
>
> >         @Override
> >         protected void onSaveInstanceState(Bundle outState) {
> >                 outState.putInt("contextMenuPosition", 
> > mContextMenuPosition);
> >         }
>
> >         @Override
> >         protected void onRestoreInstanceState( Bundle inState ){
> >                 if ( inState.containsKey("contextMenuPosition") ) {
> >                         mContextMenuPosition = 
> > inState.getInt("contextMenuPosition");
> >                 }
> >         }
>
> >         @Override
> >         protected void onResume() {
> >             super.onResume();
> >             if ( mContextMenuPosition > 0 ) {
> >                 openContextMenu(getListView());
> >         }
> >     }
>
> > };
>
> I'm also looking for a way to avoid the ContextMenu to disappear when
> screen rotates.
>
> Anyone did it?


Found the solution.

Check:

 * 
http://stackoverflow.com/questions/1664472/persisting-a-context-menu-after-screen-rotation/1673374#1673374

 * http://www.devx.com/wireless/Article/40792/1763/page/5

 * 
http://stackoverflow.com/questions/456211/activity-restart-on-rotation-android

Hope it's useful.

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to