你好,我有一些问题。任何人都可以帮助我
答案 0 :(得分:1)
您想要使用传递给onActivityResult
的意图。
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 1)
{
String str = data.getExtras().getString("name");
TextView t = (TextView) findViewById(R.id.textView1);
t.setText(str);
}
else
{
}
}
答案 1 :(得分:1)
String str = data.getExtras().getString("name");
TextView t = (TextView) findViewById(R.id.textView1);
t.setText(str);
试试这个,不要再次调用getIntent()。
答案 2 :(得分:1)
潜在问题:
答案 3 :(得分:0)
答案 4 :(得分:0)
在Activity One中,您需要使用startActivityWithResult()调用Activity Two,如:
Intent i = new Intent(this, ActivityTwo.class);
startActivityForResult(i, ACTIVITY_TWO_REQUEST_CODE);
然后在活动二中,您将在完成活动时发回结果:
Intent data = new Intent();
data.putExtra("ACTIVITY_TWO_KEY", "Here is your value");
setResult(Activity.RESULT_OK, data);
finish();
然后回到Activity One,你会想要覆盖onActivityResult,如下所示:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (REQUEST_CODE) {
case ACTIVITY_TWO_REQUEST_CODE:
if (resultCode == Activity.RESULT_OK) {
//Load your text into your TextView from Activity Two
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}