当我点击屏幕上的按钮时,我想关闭我的应用程序。
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();
}
};
我做了这个活动,但当我点击按钮时,应用程序仍然出现在最近的应用程序菜单上,我不知道为什么。
答案 0 :(得分:0)
试试这个:
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
System.exit(0);
}
答案 1 :(得分:0)
最佳方法是将用户带到Launcher / Home。
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);