2015年2月16日 星期一

避免不小心離開APP

 https://gist.github.com/adsl99801/a64698938d097bed612a#file-gistfile1-java
 private void backKeyPressed(){
 
backKeyPressedCount++;
 
Utils.log("getBackStackEntryCount:" + getChildFragmentManager().getBackStackEntryCount()+",backKeyPressedCount:"+backKeyPressedCount);
 
if (backKeyPressedCount<4) {
 
getChildFragmentManager().popBackStack();
 
showSecondLayout();
 
return;
 
}
 
FinishAppListener finishAppListener = new FinishAppListener() {
 
@Override
 
public void onClick(DialogInterface dialog, int which) {
 
if(which== AlertDialogWhich.Y){
 
EventBus.getDefault().unregister(this);
 
dialog.dismiss();
 
getActivity().finish();
 
}
 
}
 
};
 
resetBackKeyPressedCount();
 
Utils.showAlertDialog(v.getContext(), getResources().getString(R.string.askExistApp),finishAppListener);
 
}

沒有留言:

張貼留言