android - Passing parameters to Fragment at creation time -


this question has answer here:

i'm new android programming , i'm studying components , architecture.

i'm testing fragments.

i need pass list of custom objects activity nested fragment.

i read question: how pass variable activity fragment, , pass back? , noticed bundle collection best practice pass parameters during fragment creation.

bundle bundle = new bundle(); string mymessage = "stackoverflow cool!"; bundle.putstring("message", mymessage ); fragmentclass fraginfo = new fragmentclass(); fraginfo.setarguments(bundle); 

but i'm wondering why can't pass parameters via constructor, say:

list<customobject> myparameter = new arraylist<customobject>(); myfragment fraginfo = new myfragment(myparameter); // custom fragment constructor 

is wrong approach? empty constructor used framework instantiate fragment via reflection or similar?

at time when android wants recreate fragment (i.e. app comes background foreground), use default no-argument constructor (without parameters). should not overload constructor.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -