android - Passing parameters to Fragment at creation time -
this question has answer here:
- do fragments need empty constructor? 4 answers
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
Post a Comment