Issue
I'm trying to pass data from an ArrayList to multiple activities, but I can't get it to work. This is some of my code (simplified):
public class firstClass{
ArrayList<String> listOfNames = new ArrayList<String>();
Intent intent = new Intent(getApplicationContext(), secondClass.class);
Intent intent2 = new Intent(getApplicationContext(), thirdClass.class);
intent2.putStringArrayListExtra("listOfNames", listOfNames)
intent.putStringArrayListExtra("listOfNames", listOfNames);
...
startActivity(intent);
So I want to go the activity I started, but want to send the data not only to this activity, but also another one. In both these classes I have the following code:
Intent i = getIntent();
listOfNames = i.getStringArrayListExtra("listOfNames");
The the second class does have the list I need (because I started it immediately), but the third class doesn't. The problem is I don't want to start the third class immediately. How can I fix this?
I've also tried to start the third class from the second class and passing the data from the second class (so from first class to second class to third class), but this doesn't work either because I remove items from the list in the second class but I want the full list to reach the third class.
Thanks,
Koen
Solution
I've also tried to start the third class from the second class and passing the data from the second class (so from first class to second class to third class), but this doesn't work either because I remove items from the list in the second class but I want the full list to reach the third class.
So make a copy of the list first ...
Modify one copy of the list in the second class and send the other copy that remains a full list on to the 3rd class.
Answered By - dominicoder
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.