代码之家  ›  专栏  ›  技术社区  ›  jul

启动“设置”活动后,如何返回主要活动?

  •  0
  • jul  · 技术社区  · 15 年前

    startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS)
    

    谢谢

    七月

    1 回复  |  直到 15 年前
        1
  •  2
  •   Cristian    15 年前

    在这种情况下,用户必须显式地返回到您的活动(例如,按几次back按钮)。我通常第一次做这个 Activity 在这种情况下:

    @Override
    public void onResume(){
        super.onResume();
        // first, check connectivity
        if ( isOnline ){
            // do things if it there's network connection
        }else{
            // as it seems there's no Internet connection
            // ask the user to activate it
            new AlertDialog.Builder(SplashScreen.this)
                .setTitle("Connection failed")
                .setMessage("This application requires network access. Please, enable " +
                        "mobile network or Wi-Fi.")
                .setPositiveButton("Accept", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // THIS IS WHAT YOU ARE DOING, Jul
                        SplashScreen.this.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
                    }
                })
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        SplashScreen.this.finish();
                    }
                })
                .show();
        }
    }
    

    如你所见,我检查了 onResume