I have a FloatWindow,it has a static method with view.Button OnClickListener
,
I want Show Dialog in any Activity When I Click the View,But the Context can't not used the getApplicationContext
, it will Show "Unable to add window token null is not for an application"
, So How do I get the Activity context when I Click the View?
//the Para is getapplicationcontext,but is not work
public static void createStatusWindow(Context context) {
WindowManager windowManager = getWindowManager(context);
int screenWidth = windowManager.getDefaultDisplay().getWidth();
int screenHeight = windowManager.getDefaultDisplay().getHeight();
if (statusWindow == null) {
LayoutInflater mInflater = LayoutInflater.from(context);
statusWindow = mInflater.inflate(R.layout.floatwindow, null);
statusWindow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
MessageBox.show("GPS Status", "Good", MessageBox.Icon.Alert,context,true);
}catch (Exception e){
e.printStackTrace();
}
}
});
}
try using
yourActivityName.this
in place ofgetApplicationContext()