0

在我的活动中,我建议用户使用这种方法激活他的互联网连接:

    public static void showNoConnectionDialog(Context ctx1) {
    final Context ctx = ctx1;
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setCancelable(true);
    builder.setMessage("This requires network access. Please, enable your mobile network or Wi-Fi.");
    builder.setTitle("No internet connection");
    builder.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            ctx.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
        }
    });
    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            return;
        }
    });
    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            return;
        }
    });

    builder.show();
}

它工作正常!问题是当我按下后退按钮时,我无法回到我的活动,因为有一个“finish();” 我的 onPause 方法中的方法......事情是,如果用户以另一种方式退出活动,但当我建议他在上面显示的对话框中激活互联网时,我想保留这个 finish() 方法......

我怎么能那样做?我应该在我的 onpause 方法中设置一些条件还是有其他方法?

4

0 回答 0