简体   繁体   English

将数据从第二个活动中的 ArrayList 移动到主要活动 - android

[英]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.

相关问题 使userInput从主要活动显示在Android的第二个活动中 - Making userInput from main activity to display on second activity in Android Android微调器将数据从活动转移到另一个 - Android spinners moving data from activity to another 如何从第二个活动中获取 ArrayList 并将其显示在主活动的 Recycler 视图中 - How to get ArrayList from second Activity and show it in a Recycler view in the Main Activity Android Studio - 如何从 RecyclerView 中的 EditText 获取数据并将它们放入主要活动中的 ArrayList? - Android Studio - How to get data from an EditText in a RecyclerView and put them into an ArrayList in the main activity? 传递ArrayList <Object> 返回主要活动(Android) - Passing ArrayList<Object> back to main Activity (Android) RecyclerView-使用第二个活动的数组列表作为数据 - RecyclerView - Use an Arraylist of second activity as data 无法将数据从第二个活动传递到主活动 - Can't pass data from second Activity to main 将数据从第二个活动传递到第三个活动 - Passing data from second activity to third activity 将数据从第二个活动移到第一个活动 - Move Data from Second Activity to first Activity 将数据从 Main 活动保存到 ListView 活动 - Save data from Main activity to a ListView activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM