Android Fragments - newInstance vs instantiate method -
are there (dis-)advantages utilize instantiate method loading new fragments? or on personal taste?
bundle args = new bundle(); args.pustring(...); args.... fragment newfragment = fragment.instantiate(this, fragmentname, args);
vs
//... newfragment instance = newfragment.newinstance(string param1, string param2); //.... public static newfragment newinstance(string param1, string param2) { newfragment fragment = new newfragment(); bundle args = new bundle(); args.putstring(arg_param1, param1); args.putstring(arg_param2, param2); fragment.setarguments(args); homecoming fragment; }
using newinstance()
preferable if have arguments must provided fragment, it's easy see parameters needed, , don't have worry creating bundle , knowing keys use.
if fragment takes no arguments, avoid altogether , create default constructor, i.e. new myfragment()
.
android android-fragments
No comments:
Post a Comment