How to pass value from global variable application into fragment? I got null value error message.
Caused by: android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
Global Variable
public class Gl extends Application {
private String token = "bla bla";
public void setToken(String token){
this.token = token;
}
public String getToken() {
return token;
}
}
Fragment
public class MyFragment extends Fragment {
private String token;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
token = ((Gl) getActivity().getApplicationContext()).getToken();
}
/* .... */
}