[英]Moving Data from ArrayList in Second activity to main activity - android
I want to move data from an ArrayList in a second activity to my main activity.我想将数据从第二个活动中的 ArrayList 移动到我的主要活动。
This is my main.java file这是我的 main.java 文件
super.onActivityResult(requestCode, resultcode, data);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.callingOrder);
ArrayList<String> numbersList = (ArrayList<String>) getIntent().getSerializableExtra("key");
textView.setText(String.valueOf(numbersList));```
public void onBackPressed(){
Intent intent = new Intent();
intent.putExtra("key", sandwichOrder);
setResult(RESULT_OK, intent);
finish();
the second.java file above ^上面的第二个.java文件^
I only get a null message on my xml file.我的 xml 文件只收到一条空消息。 Point is to move the data when I press the back arrow button.
要点是当我按下后退箭头按钮时移动数据。
In this line, you're looking in the wrong Intent
:在这一行中,您正在寻找错误的
Intent
:
ArrayList<String> numbersList = (ArrayList<String>) getIntent().getSerializableExtra("key");
getIntent()
will return the Intent that was used to start your activity. getIntent()
将返回用于启动您的活动的 Intent。 Anything you pass "back" with setResult()
will be in the data
parameter to onActivityResult()
.您使用
setResult()
“返回”的任何内容都将包含在onActivityResult()
的data
参数中。 So write this instead:所以写这个:
ArrayList<String> numbersList = (ArrayList<String>) data.getSerializableExtra("key");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.