I want to show an alert window to ask a question to user. I am using the code given below. I get the following error:
Window type can not be changed after the window is added.
try {
final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
WindowManager wm = (WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE);
ViewGroup mTopView = (ViewGroup) getLayoutInflater().inflate(R.layout.dialog_subscription_buy, null);
getWindow().setAttributes(params);
wm.addView(mTopView, params);
} catch (Exception ex) {
ex.printStackTrace();
}
How can I fix it or is there any solution to ask a question to user on top of all activities?
Note: I granted user with this Manifest permission rule:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />