1

In my MainActivity, I have 4 fragments. When I rotated the screen, new Fragment objects will be recreated, that makes my app very slow, sometimes it generated Android not responding. Could you tell me a way to fix it?

In MainActivity.java:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (homeFragment == null) {
            homeFragment = new HomeFragment(this);
        }
        
        if (photoFragment == null) {
            photoFragment = new PhotoFragment(this);
        }
        
        if (videoFragment == null) {
            videoFragment = new VideoFragment(this);
        }  
        
        if (settingFragment == null) {
            settingFragment = new SettingFragment(this);
        }
        ....
     }

soiXam
  • 33
  • 1
  • 5
  • 1
    is it what you are looking for? https://stackoverflow.com/questions/10634854/android-fragments-recreated-on-orientation-change – Dion Saputra Nov 28 '20 at 03:34

0 Answers0