0

I have a DialogFragment that own 2 inner Fragments (which are displayed as tabs in a ViewPager).

The DialogFragment is called as usual, using a newInstance() pattern, with a Bundle containing a simple int (an id, for database fetching). It then calls its 2 Fragments, which will need the int.

I have 2 options here :

  • having a static int field of my DialogFragment, which would be instanciated in onCreateView() when I getArguments(), and read inside my inner Fragments
  • using another newInstance() pattern inside my inner fragments and passing the int along

What's the difference between these 2 ways ?

Dan Chaltiel
  • 7,811
  • 5
  • 47
  • 92

1 Answers1

0

In your case, both of them are okey. Personally, I'd rather use the newInstance() approach, since I think is cleaner.

Also, keep in mind that static objects in Android are reclaimed when the app is destroyed, and not before.

Community
  • 1
  • 1
FlyingPumba
  • 1,015
  • 2
  • 15
  • 37