android - WindowManager null -
i written separate class of adapter gridview present in fragment. if called windowmanger first time adapter constructor worked if changed orientation windowmanager becomes null.
i written code getting window manager like
public calendaradapter(context c, calendar monthcalendar) { getwindowdimension(); } void getwindowdimension() { display display = (((activity)mcontext).getwindowmanager().getdefaultdisplay()); windowheight = display.getheight(); windowwidth = display.getwidth(); }
even tried getsystemservice(window_service)
i think problem because of activity recreation. not getting window of activity if not created. throws nullpointer exception window manager.
in manifest activity has flags :
android:configchanges="orientation|screenlayout|navigation|layoutdirection"
please same.
my guess when calling mcontext.getwindowmanager() after rotation mcontext hasn't yet been attached window, see activity.onattachedtowindow. if calling inside fragment, wanting ensure aren't calling until onfragmentattached.
in short, want set adapter little bit later in fragment life-cycle.
Comments
Post a Comment