Android:设置wifi后返回App [英] Android: Back to App after setting wifi

查看:790
本文介绍了Android:设置wifi后返回App的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在myActivity中,这是我的代码,用于检查手机是否连接到Internet.

In myActivity, This is my code to check if my phone connect to the Internet or not.

if (!isConnected()) {
            // super.playingVideo.setVideoUrl(product.getVideoUrl());
            String message = getResources().getString(R.string.wifi_prompt);
            super.showDialog(this, message, R.string.wifi_setting,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            if (dialog != null) {
                                dialog.dismiss();
                            }
                            currentProduct = product;
                            isViewRequest = true;
                            startActivity(new Intent(
                                    android.provider.Settings.ACTION_WIRELESS_SETTINGS));

                        }
                    }, R.string.back, dismissDialogListener);
        } else {...}

然后到简历:

@Override
protected void onResume() {
    // After setting wifi
    if (isViewRequest) {
        ...//mycode
    }
    super.onResume();
}

我的问题是,当我完成设置wifi连接并按返回按钮时.它返回到手机的菜单屏幕,而不是恢复myActivity. 只有在此之后再次启动我的应用程序时,才会执行onResume()函数.
那么,设置wifi后,我想回到我的应用程序时会丢失什么呢?

My problem is, when I've done setting wifi connection and press back button. It back to the menu screen of my phone, not resume myActivity. Only if I launch my app again after that, the onResume() function is executed.
So, what's my missing to back to my app after setting wifi?

推荐答案

我认为这是您的答案,您必须将设置打开为ActivityForResult:

this is your answer I think , you have to open the settings as ActivityForResult :

startActivityForResult(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS), 0);

您可以像这样在AlertDialog中实现它:

You can implement it in an AlertDialog like this:

AlertDialog.Builder alertDialog = new AlertDialog.Builder(
                this);

        // Setting Dialog Title
        alertDialog.setTitle("Confirm...");

        // Setting Dialog Message
        alertDialog.setMessage("Do you want to go to wifi settings?");

        // Setting Icon to Dialog
        // alertDialog.setIcon(R.drawable.ic_launcher);

        // Setting Positive "Yes" Button
        alertDialog.setPositiveButton("yes",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        // Activity transfer to wifi settings
                        startActivityForResult(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS), 0);
                    }
                });

        // Setting Negative "NO" Button
        alertDialog.setNegativeButton("no",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // Write your code here to invoke NO event

                        dialog.cancel();
                    }
                });

        // Showing Alert Message
        alertDialog.show();

这篇关于Android:设置wifi后返回App的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆