android - Is is better to add fragments to an activity by <fragment> tags in xml or by FragmentManager in a code? -


i've started developing android apps , wondering way better in case of adding fragments activity. let's assume view activity contain 3 fragments. won't changed. same. better add them tags or include them in activity code?

and second question issue: let's have activity fragment list. when clicked on item want show new view. can replace list fragment new different fragment? if answer yes better creating new activity?

thanks replies

which way better in case of adding fragments activity

one approach not 'better' other - both serve own purposes, static vs. dynamic comparison.

for example, fragments declared in layout cannot given arguments using setarguments(). such fragment can not replaced fragment: if it's part of layout, it'll there. of course can still show/hide instance, attempting remove through fragmenttransaction not work. static elements easier work though, because have well-defined lifetime , behaviour.

regarding second question: yes, that's possible. developers build app around single activity container, swapping out fragments user navigates way through content. in cases, user's point of view, there little difference between doing or having multiple activities. important thing keep in mind choose approach you're comfortable with, doesn't overly complicate things , takes advantage of patterns explained in implementing effective navigation.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -