Java 通过3个元素(意图)

Java 通过3个元素(意图),java,android,string,android-intent,bundle,Java,Android,String,Android Intent,Bundle,我想将以下三个要素从一个活动传递到另一个活动: String a = "a"; String b = "b"; String c = "c"; 我尝试了以下方法,但没有成功: 在主活动(主活动)中: 在子活动(子活动)中: 在子活动中,您应该通过调用getIntent().getExtras()获取捆绑包,而不是通过创建新的捆绑包 public class SubActivity extends Activity { public void onCreate(Bundle saved)

我想将以下三个要素从一个活动传递到另一个活动:

String a = "a";
String b = "b";
String c = "c";
我尝试了以下方法,但没有成功:

在主活动(主活动)中:

在子活动(子活动)中:


在子活动中,您应该通过调用
getIntent().getExtras()获取捆绑包,而不是通过创建新的捆绑包

public class SubActivity extends Activity {
    public void onCreate(Bundle saved) {
        super.onCreate(saved);
        setContentView(...);

        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            // call extras.getString() here
        }
    }
}
在活动B中:

Bundle extras = getIntent().getExtras();
String[] arrayB = extras.getStringArray("array");
在你的亚活动中

而不是

 Bundle extras = new Bundle();  
使用下面的

 Bundle extras = getIntent().getExtras();
 if(extras!=null)
 {
       String a = extras.getString("a");
       String b = extras.getString("b");
       String c = extras.getString("c");
 } 
Bundle extras = getIntent().getExtras();
String[] arrayB = extras.getStringArray("array");
 Bundle extras = new Bundle();  
 Bundle extras = getIntent().getExtras();
 if(extras!=null)
 {
       String a = extras.getString("a");
       String b = extras.getString("b");
       String c = extras.getString("c");
 }