![](/img/trans.png)
[英]How do I pass string from SecondActivity to MainActivity on Android Studio?
[英]How to add values from MainActivity to list in SecondActivity
我在将值添加到SecondActivity中的列表时遇到问题。 在MainActivity中,我在EditText框中设置文本并发送给第二类。 第一次添加值,但是当我回到上一个活动,又一次设置文本并发送时,列表中的值将被替换,而不是添加。 有人知道这个问题的根源是什么?
在第一个活动中尝试以下方法:
String[] array = {"Hi", "there", "yeah"};
Intent goIntent = new Intent(this, NewAppActivity.class);
/*
* put extra with "array" as a key and the String[] with your values as the value to pass
* */
goIntent.putExtra("array", array);
startActivity(goIntent);
在第二个活动中:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String[] array = extras.getStringArray("array");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.