0

I try to pass three arrays to other activity, but for whatever reason it seems like only one last array passed from the parent activity goes to the child and the rest dont Here is the parent activity code:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_category_list_items);

    Intent intent = getIntent();
    categoryTitle = intent.getStringExtra(categoryName);

    if(Arrays.asList(FragmentHelper.Days).contains(categoryTitle)) {
        header.setText("Start the workout");
        addButton.setText("Start");
        addButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Context context = v.getContext();
                Intent intent = new Intent(context, ItemDetailActivityCopy.class);
                Bundle extras = new Bundle();
                List<ListItem> items = listManager.getList(categoryTitle);
                ArrayList<String> itemName = new ArrayList<>();
                ArrayList<String> itemTime = new ArrayList<>();
                ArrayList<String> itemNumberOfSets = new ArrayList<>();

                for(int i = 0; i < listManager.getNumberOfItemsCopy(categoryTitle); i++) {
                    itemName.add(items.get(i).getDescription());
                    itemTime.add(String.valueOf(items.get(i).getTime()));
                    itemNumberOfSets.add(String.valueOf(items.get(i).getNumberOfSets()));
                }
                Log.d("Title:", itemName.toString());
                Log.d("Time:", itemTime.toString());
                Log.d("Num of sets:", itemNumberOfSets.toString());
                extras.putStringArrayList(ItemDetailActivityCopy.itemName.toString(), itemName);
                extras.putStringArrayList(ItemDetailActivityCopy.itemTime.toString(), itemTime);
                extras.putStringArrayList(ItemDetailActivityCopy.itemNumberOfSets.toString(), itemNumberOfSets);
                intent.putExtras(extras);
                context.startActivity(intent);
            }
        });
    }
}
Oleh
  • 1
  • 3
  • Possible duplicate of [How to pass an ArrayList to another activity and convert it into double](http://stackoverflow.com/questions/22640669/how-to-pass-an-arrayliststring-to-another-activity-and-convert-it-into-double) – Asif Patel Apr 10 '17 at 21:00
  • 2
    "the rest dont" -- how have you determined this? Where is your code for retrieving values from the extras? Note that the keys to your extras are rather strange. Usually, we use constants, not `toString()` of some other object. – CommonsWare Apr 10 '17 at 21:01
  • Possible duplicate of [Passing and ArrayList through intent](http://stackoverflow.com/questions/41014704/passing-and-arraylistservice-through-intent) – Saurabh Bhandari Apr 11 '17 at 05:08

1 Answers1

0

pass ArrayList<String> from one Activity to other Activity,using putStringArrayListExtra

Intent intent = new Intent(context, ItemDetailActivityCopy.class);
intent.putStringArrayListExtra("LIST_ITEMS", itemName);
startActivity(intent);

get ArrayList<String> from other Activity,

ArrayList<String> listItems;
listItems = getIntent().getStringArrayListExtra("LIST_ITEMS");
Narendra Sorathiya
  • 3,770
  • 2
  • 34
  • 37