8

我是 android 新手,我使用意图将数据从一个 Activity 传输到另一个 Activity。我只是想知道对象引用或对象副本是否正在发送到第二个 Activity。

4

2 回答 2

6

Intent.putExtra 发送对象的副本,当您从那里获得新引用的意图中获得额外的引用时,它不是同一个引用

于 2013-04-05T05:29:37.110 回答
1

intent.putExtra 用于在 Activity 之间发送信息。这是一个例子

使用它来“放置”文件

Intent i = new Intent(FirstScreen.this, SecondScreen.class);   
String keyIdentifer  = null;
i.putExtra("STRING_I_NEED", strName);

然后,要检索该值,请尝试以下操作:

String newString
if (savedInstanceState == null) {
    extras = getIntent().getExtras();
    if(extras == null) {
        newString= null;
    } else {
        newString= extras.getString("STRING_I_NEED");
    }
} else {
    newString= (String) savedInstanceState.getSerializable("STRING_I_NEED");
}
于 2013-04-05T05:47:04.720 回答