安卓,退出确认弹窗

 

// ---------------------------------------------------------------------
	
//	 CallBackF call = new CallBackF()
//	 {
//		 @Override
//		 public void F()
//		 {
//			 // 退出逻辑
//		 }
//	 };
//	
//	 QuitCustom(activity, call);

public interface CallBackF
{
	// 回调处理逻辑
	public void F();
}

// demo自定义退出逻辑
public static void QuitCustom(Context context, final CallBackF call)
{
	AlertDialog.Builder dialog = new AlertDialog.Builder(context);
	dialog.setTitle("确认退出?");
	dialog.setIcon(android.R.drawable.ic_dialog_info);
	dialog.setPositiveButton("确定", new DialogInterface.OnClickListener()
	{
		@Override
		public void onClick(DialogInterface dialog, int which)
		{
			if (call != null)			// 执行回调处理逻辑
				call.F();
			else System.exit(0);		// 退出运行
		}
	});
	
	dialog.setNegativeButton("取消", new DialogInterface.OnClickListener()
	{
		@Override
		public void onClick(DialogInterface dialog, int which)
		{
			// 点击“返回”后的操作,这里不设置没有任何操作
		}
	});
	
	dialog.show();
}

猜你喜欢

转载自blog.csdn.net/scimence/article/details/85290844