Alternative to getDeclaredField("mBase") on Android 5 -


on android 4.4 , below using following code setaccessible(true) , context dialog:

    private context getoriginalcontextfordialog(dialog dialog) {     try {         if (dialog == null || (dialog != null && dialog.getcontext() == null)){             return null;         }          field field = dialog.getcontext().getclass().getdeclaredfield("mbase");          field.setaccessible(true);         context value = (context) field.get(dialog.getcontext());         return value;     } catch (exception e) {         logproc.errsys(logsubcategory.user_notice, "error getting dialog context on uiprocimpl.dismissprogressdialog.", e);     }      return null; } 

this returns exception in android 5 because "mbase" not found. cannot find out equivalent on android 5. added "getdeclaredfields" see values returned. attached screenshots of of data in array returned "getdeclaredfields". have highlighted red in screenshot android 4.4 shows "mbase". other screenshot android 5 , not include "mbase".

what equivalent "mbase" in android 5? or how should better code support both 4.4 , 5?

android 4.4 android 4.4

android 5 android 5

you can use base context dialog:

dialog dialog; // dialog context context = dialog.getcontext(); if(context instanceof contextwrapper) {      context = ((contextwrapper)context).getbasecontext(); }  return context; 

edit:

instanceof operator used check if object instance of class.

example:

context context = dialog.getcontext(); if(context instanceof arraylist){ // false because context not instance of arraylist }  object object = context; if(object instanceof context){ // true   } 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -