Help passing an ArrayList of Objects to a new Activity

前端 未结 10 2201
眼角桃花
眼角桃花 2020-11-28 08:53

I have an arraylist of objects. ie ArrayList.

I want to pass this to a new Activity. I tried to use putParcelableArrayList but it has issues with the object. I remov

10条回答
  •  自闭症患者
    2020-11-28 09:14

    I was struggling with same issue and found a much better approach of putting my array in Global Class that can be accessed across all activities. Thanks to this post for describing how to use global variables that can be accessed across multiple activities.

    My global class is

    public class GlobalClass extends Application{ public MyObject[] objArray }

    Android Manifest Change

    android:name=".GlobalClass"
    

    Accessed in multiple activities as

    GlobalClass g = (GlobalClass)getApplicationContext();
    g.objArray[0].x = 100;
    int x = g.objArray[0].x;
    

    For Better understanding please go through the post.

提交回复
热议问题