android - How to pause/resume a fragment -


background: wrote custom container capable of holding 3 fragments. depending on state of container 2 or 3 fragments visible. inform fragments visibility changed tried out 2 options:

  1. i called fragment.setuservisiblehint() method respective value. hosted fragments overrode method , react appropriately. worked out.

  2. i called fragmenttransaction.hide() , fragmenttransaction.show() methods hide , show fragments. hosted fragments overrode fragment.onhiddenchanged() , reacted needed. worked out well.

my problem not satisfied either of these options. put invisible fragment standard paused state. advantage of option keep code clean , simple, don't need override special methods (like setuservisiblehint() or onhiddenchanged()) , can handle inside onpause() , onresume() implemented.

question: proper way put fragment paused state , resume state?

update: tried out fragmenttransaction.detach() too. not option because destroys view, not allowed in case.

sounds want call fragmenttransaction#attach , fragmenttransaction#detach put fragment through life-cycle routines same fragmentpageradapter (see source here).

detaching fragment detach() put fragment through onpause, onstop , ondestroyview life-cycle methods, , when re-attach attach() go through oncreateview, onstart , onresume life-cycle methods.

you must make sure using tag's as-well container-id since can have multiple fragments attached single container , have able fragment reference fragmentmanager have done via tag.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -