来自 MainActivity 的 Intent 能否用于 Android 中的 2 个不同 Activity?
Can an intent from MainActivity be used in 2 different Activities in Android?
在我的 MainActivity 中,我有以下
Intent myintent=new Intent(MainActivity.this, DisplayInformation.class);
myintent.putExtra("displayName",userName.getText().toString());
myintent.putExtra("displayContact",userContact.getText().toString());
myintent.putExtra("displayAddress",userAddress.getText().toString());
myintent.putExtra("displayStore",userStore.getSelectedItem().toString());
myintent.putExtra("displayRequest",userRequest.getText().toString());
startActivity(myintent);
我可以在我的 SecondActivity 中正确显示它,这是代码
TextView textView1 = (TextView)findViewById(R.id.textView1);
TextView textView2 = (TextView)findViewById(R.id.textView2);
TextView textView3 = (TextView)findViewById(R.id.textView3);
TextView textView4 = (TextView)findViewById(R.id.textView4);
TextView textView5 = (TextView)findViewById(R.id.textView5);
textView1.setText(getIntent().getStringExtra("displayName"));
textView2.setText(getIntent().getStringExtra("displayContact"));
textView3.setText(getIntent().getStringExtra("displayAddress"));
textView4.setText(getIntent().getStringExtra("displayStore"));
textView5.setText(getIntent().getStringExtra("displayRequest"));
Intent myintent=new Intent(DisplayInformation.this, Confirmation.class);
myintent.putExtra("confirmID",smsCode.getText().toString());
startActivity(myintent);
问题是当我在我的 ThirdActivity 中使用它时,它不起作用。
TextView textView2 = (TextView)findViewById(R.id.confirmName);
TextView textView3 = (TextView)findViewById(R.id.confirmContact);
TextView textView4 = (TextView)findViewById(R.id.confirmAddress);
TextView textView5 = (TextView)findViewById(R.id.confirmStore);
TextView textView6 = (TextView)findViewById(R.id.confirmRequest);
textView2.setText(getIntent().getStringExtra("displayName"));
textView3.setText(getIntent().getStringExtra("displayContact"));
textView4.setText(getIntent().getStringExtra("displayAddress"));
textView5.setText(getIntent().getStringExtra("displayStore"));
textView6.setText(getIntent().getStringExtra("displayRequest"));
没有任何错误。只是它没有显示 ThirdActivity 中的值。知道如何去做吗?我想在 ThirdActivity 中显示相同的信息。
它没有显示任何内容,因为第二个 Intent 不包含您尝试获取的值。实际上,您只将 "confirmID" 值放入第二个 Intent 中。如果你还想要其他值,你甚至必须在第二个 Intent 中设置它们,就像你对第一个 Intent 所做的一样。
在发送到 Third 之前,您必须将所有数据再次放入 Intent activity。
Intent myintent = new Intent(DisplayInformation.this, Confirmation.class);
myintent.putExtra("confirmID", smsCode.getText().toString());
myintent.putExtra("displayName", textView1.getText().toString());
myintent.putExtra("displayContact", textView2.getText().toString());
myintent.putExtra("displayAddress", textView3.getText().toString());
myintent.putExtra("displayStore", textView4.getSelectedItem().toString());
myintent.putExtra("displayRequest", textView5.getText().toString());
startActivity(myintent);
在我的 MainActivity 中,我有以下
Intent myintent=new Intent(MainActivity.this, DisplayInformation.class);
myintent.putExtra("displayName",userName.getText().toString());
myintent.putExtra("displayContact",userContact.getText().toString());
myintent.putExtra("displayAddress",userAddress.getText().toString());
myintent.putExtra("displayStore",userStore.getSelectedItem().toString());
myintent.putExtra("displayRequest",userRequest.getText().toString());
startActivity(myintent);
我可以在我的 SecondActivity 中正确显示它,这是代码
TextView textView1 = (TextView)findViewById(R.id.textView1);
TextView textView2 = (TextView)findViewById(R.id.textView2);
TextView textView3 = (TextView)findViewById(R.id.textView3);
TextView textView4 = (TextView)findViewById(R.id.textView4);
TextView textView5 = (TextView)findViewById(R.id.textView5);
textView1.setText(getIntent().getStringExtra("displayName"));
textView2.setText(getIntent().getStringExtra("displayContact"));
textView3.setText(getIntent().getStringExtra("displayAddress"));
textView4.setText(getIntent().getStringExtra("displayStore"));
textView5.setText(getIntent().getStringExtra("displayRequest"));
Intent myintent=new Intent(DisplayInformation.this, Confirmation.class);
myintent.putExtra("confirmID",smsCode.getText().toString());
startActivity(myintent);
问题是当我在我的 ThirdActivity 中使用它时,它不起作用。
TextView textView2 = (TextView)findViewById(R.id.confirmName);
TextView textView3 = (TextView)findViewById(R.id.confirmContact);
TextView textView4 = (TextView)findViewById(R.id.confirmAddress);
TextView textView5 = (TextView)findViewById(R.id.confirmStore);
TextView textView6 = (TextView)findViewById(R.id.confirmRequest);
textView2.setText(getIntent().getStringExtra("displayName"));
textView3.setText(getIntent().getStringExtra("displayContact"));
textView4.setText(getIntent().getStringExtra("displayAddress"));
textView5.setText(getIntent().getStringExtra("displayStore"));
textView6.setText(getIntent().getStringExtra("displayRequest"));
没有任何错误。只是它没有显示 ThirdActivity 中的值。知道如何去做吗?我想在 ThirdActivity 中显示相同的信息。
它没有显示任何内容,因为第二个 Intent 不包含您尝试获取的值。实际上,您只将 "confirmID" 值放入第二个 Intent 中。如果你还想要其他值,你甚至必须在第二个 Intent 中设置它们,就像你对第一个 Intent 所做的一样。
在发送到 Third 之前,您必须将所有数据再次放入 Intent activity。
Intent myintent = new Intent(DisplayInformation.this, Confirmation.class);
myintent.putExtra("confirmID", smsCode.getText().toString());
myintent.putExtra("displayName", textView1.getText().toString());
myintent.putExtra("displayContact", textView2.getText().toString());
myintent.putExtra("displayAddress", textView3.getText().toString());
myintent.putExtra("displayStore", textView4.getSelectedItem().toString());
myintent.putExtra("displayRequest", textView5.getText().toString());
startActivity(myintent);