How to modified an ArrayList for ListView but ListView and ArrayList in different Activity

I will explain my problem

I have 2 class :

  • MyListViewClassActivity (implements Serializable so it can parse using intent putExtra)
  • MyOtherClassActivity

Inside MyListViewClassActivityi handling ListView and initial ArrayList called alMyData

And MyListViewClassActivity will intent/called new activity called MyOtherClass, i will putExtra alMyData (i can tell you alMyData parsing correctly with all data inside it)

MyOtherClassActivity will add new data to alMyData.

I will close MyOtherClassActivity so it appear again MyListViewClassActivity. Inside MyListViewClassActivity have onResume that adapter.notifyDataSetChanged.

My Problem :

When onResume inside MyListViewClassActivity the data not increase, i can sure already add new data in MyOtherClassActivity.

Why ? Please give me explanation and solution.

Thank you.

I think you don’t really understand android and how it works. You should not pass your data list trhough the extra.

Look at MVC pattern, Android is a kind of MVC (not quiet but still thta could help you understand the mechanics).

You should have a model for your data. And then your activitie sworks as controllers.

You can look at RecyclerView too. This a proper way to display list on androdi. And moreover if you use Android Studio (I’m pretty sure you do) you can generate them with efault models and all the stuff you need.

Edit :
What i was proposing is that you use that kind of class

package com.polytech.unice.tobeortohave.compare.dummy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Helper class for providing sample content for user interfaces created by
 * Android template wizards.
 * <p>
 * TODO: Replace all uses of this class before publishing your app.
 */
public class DummyContent {

/**
 * An array of sample (dummy) items.
 */
public static final List<DummyItem> ITEMS = new ArrayList<>();

/**
 * A map of sample (dummy) items, by ID.
 */
public static final Map<String, DummyItem> ITEM_MAP = new HashMap<>();

private static final int COUNT = 25;

static {
    // Add some sample items.
    for (int i = 1; i <= COUNT; i++) {
        addItem(createDummyItem(i));
    }
}

private static void addItem(DummyItem item) {
    ITEMS.add(item);
    ITEM_MAP.put(item.id, item);
}

private static DummyItem createDummyItem(int position) {
    return new DummyItem(String.valueOf(position), "Item " + position, makeDetails(position));
}

private static String makeDetails(int position) {
    StringBuilder builder = new StringBuilder();
    builder.append("Details about Item: ").append(position);
    for (int i = 0; i < position; i++) {
        builder.append("/nMore details information here.");
    }
    return builder.toString();
}

/**
 * A dummy item representing a piece of content.
 */
public static class DummyItem {
    public final String id;
    public final String content;
    public final String details;

    public DummyItem(String id, String content, String details) {
        this.id = id;
        this.content = content;
        this.details = details;
    }

    @Override
    public String toString() {
        return content;
    }
}
}

That is your model for your RecyclerView or your ListView. Of course you will need a custom Addapter to handle this data format.

But that way you can add or remove data from your list from anywhere in your app.