我有一个 android 应用程序,它在互联网连接处于活动状态时运行。当连接不可用时,会出现一个对话框,通过该对话框可以激活 wifi。在启动 wifi 连接后连接不可用时,我已让应用程序退出。问题是,我必须重新加载应用程序并在启用 wifi 后互联网连接可用时继续使用应用程序,而不是退出应用程序。
这是代码:
if (CheckConnection.checkInternetConnection(this)) {
        //load a webview and show contents from web.
   }
        else
        {
        try {
    AlertDialog alertDialog = new AlertDialog.Builder(Activity.this).create();
    alertDialog.setTitle("Info");
    alertDialog.setMessage("Internet Connection not available. Please cross check your internet connectivity and try again.");
    alertDialog.setIcon(R.drawable.error);
    alertDialog.setCanceledOnTouchOutside(false);
    alertDialog.setCancelable(false);
    alertDialog.setButton2("WiFi Setting", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName("com.android.settings", "com.android.settings.wifi.WifiSettings");
            startActivity(intent);
            System.exit(0);
        }
     });
    alertDialog.show();
    }
    catch(Exception e)
    {
    }