I want to close my application when I click the button on the screen.
public WindowManager winManager;
public RelativeLayout wrapperView;
public Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams( WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
this.winManager = ((WindowManager)getApplicationContext().getSystemService(WINDOW_SERVICE));
this.wrapperView = new RelativeLayout(getBaseContext());
getWindow().setAttributes(localLayoutParams);
View.inflate(this, R.layout.activity_main, this.wrapperView);
this.winManager.addView(this.wrapperView, localLayoutParams);
button1 = (Button)wrapperView.findViewById(R.id.button1);
button1.setOnClickListener(mButton1_OnClickListener);
}
View.OnClickListener mButton1_OnClickListener = new View.OnClickListener() {
public void onClick(final View v){
winManager.removeView(wrapperView);
wrapperView.removeAllViews();
finish();
}
};
I made this activity, but when I click on the button the application still appearing on recent apps menu and I don't know why.