Вопрос

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 {...}

And to the resume:

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

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?

Это было полезно?

Решение

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

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

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();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top