Christophe Beyls
1 min readApr 17, 2019

--

These are more general questions about Fragments.

  1. Every time you add (or replace) a new Fragment to the FragmentManager in a FragmentTransaction, you need to instantiate a new Fragment. If you use the Navigation architecture component in your project, it does it for you.
  2. Fragment instances are reused as long as they are in the FragmentManager. Once created, they can be detached/attached multiple times, meaning that their view hierarchy may be created and destroyed multiple times. Once a fragment is destroyed (onDestroy() is called) and removed from the FragmentManager, it must not be reused.

--

--

Christophe Beyls
Christophe Beyls

Written by Christophe Beyls

Android developer from Belgium, blogging about advanced programming topics.

Responses (1)