假设系统没有错误和警告,有类似的内容:
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
我的习惯对象
ErrorView.java:
public class ErrorView extends Activity{
ErrorView context;
Bundle extras;
}
LoginView.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);
}
}
}
LoginMVC.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;}
}
谢谢!
答案 0 :(得分:0)
参见http://developer.android.com/reference/android/content/Intent.html
特别是:getExtras()
。它会返回Bundle
,您可以使用Intent
putExtra()
的参数
答案 1 :(得分: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
}
答案 2 :(得分:0)
您的意思是检索已执行的意图本身的参数?
截至目前,仍无法做到这一点。