arons
arons

Reputation: 43

How to set data to fragments (setArgumets() vs setters method)

Is that compulsory to set data using bundle and set argument? What is wrong Here?

MyFragment frag = new MyFragment ()
frag.setData(mSchoolData);

//add to back stack stuff.

Upvotes: 4

Views: 1077

Answers (1)

Alécio Carvalho
Alécio Carvalho

Reputation: 13657

by using the setArgs() you will ensure that this Fragment can be recreated due to lifecycle event...while by passing arguments with your own setters it may not work properly under certain circustances. That is why it is absolutely recommended to either uset Args OR use Intent extras, these will always be automatically provided by the system if the fragment gets recreated.

Upvotes: 6

Related Questions