Reputation: 113
I have an arraylist. I get this arraylist from another activity with using Bundle
like that :
Bundle name = getIntent().getExtras();
ArrayList<String> namevalue = name.getStringArrayList("name");
I want to use same arraylist in a different class. But i can't get with using getIntent()
method becoz of my class is not an activity. Is there a way to pass this arraylist?
Upvotes: 0
Views: 1020
Reputation: 104198
You can create a setter in your class:
public class MyClass {
List<String> names;
public void setNames(List<String> names) {
this.names = names;
}
}
Then call setNames from your Activity.
Upvotes: 1
Reputation: 16449
You could pass it to the class as a parameter (via constructor or through another method):
Bundle name = getIntent().getExtras();
ArrayList<String> namevalue = name.getStringArrayList("name");
YourClass yc = new YourClass(namevalue);
Upvotes: 3