0

I have Android application with two tabs. In first tab i have fragments of Radio. This fragments are created dynamically from settings. Number of this Radio fragments is from 0 to 6, depends. In second tab I have configurationFragment's one for each Radio and I can add new. After adding or editing I need to save this to configuration and I want to recreate activity and fragments. It seems that recreate() is recreating activity, creating new Radio fragments and configurationFragment's but also old fragments still exists and call onCreateView() making some NullPointerExceptions.

How to recreate activity and destroy all old fragments and create new ones?

// SOLUTION

To properly recreate whole application just use recreate(). If you want also completly recreate your fragments, remember that your application will leave and try to use old fragments even if RetainInstance is false, just not save fields of Fragment(may throw some NullPointerExceptions if you using fields in onCreateView or other automatically called method from Activity), only views. You must detach fragments from Activity and normally create them again.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tomasz Kryński
  • 513
  • 4
  • 23

0 Answers0