public class BaseActivity extends Activity {
protected boolean isDestroy;
//防止重复点击设置的标志,涉及到点击打开其他Activity时,将该标志设置为false,在onResume事件中设置为true
private boolean clickable=true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
isDestroy=false;
requestWindowFeature(Window.FEATURE_NO_TITLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@Override
protected void onDestroy() {
super.onDestroy();
isDestroy=true;
}
@Override
protected void onResume() {
super.onResume();
//每次返回界面时,将点击标志设置为可点击
clickable=true;
}
/**
* 当前是否可以点击
* @return
*/
protected boolean isClickable(){
return clickable;
}
/**
* 锁定点击
*/
protected void lockClick(){
clickable=false;
}
@Override
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
if(isClickable()) {
lockClick();
super.startActivityForResult(intent, requestCode,options);
}
}
}
Android解决按钮重复点击问题
最新推荐文章于 2021-07-01 15:01:09 发布