0

假设系统没有错误和警告,是否有类似的东西:

Wanted_LoginController.java:

Intent intent = new Intent(loginMVC.getLoginView(),ErrorView.class);
intent.putExtra("errorMsg", errorMsg); 
loginMVC.getLoginView().startActivity(intent);

Wanted_ErrorView.java:

Intent executedIntent = getIntent();
LoginMVC loginMVC = executedIntent.getParameter1(); //will store loginMVC context from previous intent data
ErrorView errorView = executedIntent.getParameter2(); //will store errorview from previous intent data

我的自定义对象

错误视图.java:

public class ErrorView extends Activity{
  ErrorView context;
  Bundle extras;

}

登录视图.java:

public class LoginView extends ListActivity{ 
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview);
    //check the device's connection to the internet
    ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if(mWifi.isConnected()){
      new LoginController(new LoginMVC(new LoginData(), this)); //builds a new controller for the login process    
    }else{ //blocks the user to proceed to login when internet connection is not available
      finish();
      Intent intent = new Intent(this,ErrorView.class);
      intent.putExtra("errorMsg", "Please enable Wi-Fi"); 
      startActivity(intent);
    }  
  }
}

登录MVC.java:

public class LoginMVC{
  LoginData loginModel;
  LoginView loginView;
  LoginController loginController;

  public LoginMVC(LoginData pLoginModel, LoginView pLoginView, LoginController pLoginController){
    loginModel = pLoginModel;
    loginView = pLoginView;
    loginController = pLoginController;
  }

  public LoginMVC(LoginData pLoginModel, LoginView pLoginView){
    loginModel = pLoginModel;
    loginView = pLoginView;
  }

  public LoginController getLoginController(){
    return loginController;}
}

谢谢!

4

3 回答 3

0

您的意思是检索已执行意图本身的参数?

到目前为止,仍然没有办法做到这一点。

于 2013-12-19T01:19:18.877 回答
0

请参阅http://developer.android.com/reference/android/content/Intent.html 特别是:getExtras()。它返回 a Bundle,您可以从中读取添加到Intentwith的参数putExtra()

于 2013-09-01T14:36:45.200 回答
0

是的你可以。您可以在源活动中将包传递给意图,并在目标活动中获取。

这是一个例子,

//您的源活动代码:

            Bundle bundle = new Bundle();
            String s = "Hello world";
            bundle.putString("alpha", s);
            i = new Intent(this, DestinationActivity.class);
            i.putExtras(bundle);
            startActivity(i);

//您的目标活动的代码:

     Bundle  b = this.getIntent().getExtras();

    if (b.containsKey("alpha")) {

          String text = (String) getIntent().getSerializableExtra("alpha");
         // Now you can use text i.e you can show toast e.t.c


    }
于 2013-09-01T14:36:59.217 回答