Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to passing list<> in bundle

I have the following code:

List<ValueActivity> list = new ArrayList<ValueActivity>();    
list = setList();    
Intent intent = new Intent(NOTIFICATION);    
Bundle bundle = new Bundle();
bundle.put ????("list", list);
intent.putExtra("bundle", bundle);
sendBroadcast(intent);

How to write line 5 and how getExtra in destination intent

like image 494
user3016825 Avatar asked Jan 28 '15 11:01

user3016825


People also ask

How do I move a list from one activity to another activity?

You can pass an ArrayList<E> the same way, if the E type is Serializable . You would call the putExtra (String name, Serializable value) of Intent to store, and getSerializableExtra (String name) for retrieval. Example: ArrayList<String> myList = new ArrayList<String>(); intent.


2 Answers

You will need to have ValueActivity implement Parcelable interface and you will need to implement writeToParcel() the CREATOR and a suitable constructor that takes a Parcel as argument. See the documentation of Parcelable interface.

To put the list into the Bundle, use:

bundle.putParcelableArrayList("list", list);

To get the list out of the Bundle in the target activity, use:

List<ValueActivity> = listbundle.getParcelableArrayList("list");
like image 78
David Wasser Avatar answered Oct 27 '22 04:10

David Wasser


try to use :

String jsonList = gson.toJson(youList);
// Add String to bundle
like image 36
KOTIOS Avatar answered Oct 27 '22 05:10

KOTIOS