onCreate() gets called when reopen from recent task after permission settings is changed

前端 未结 3 2044
离开以前
离开以前 2021-02-20 07:44

The question title may sounds complicated but here is my situation.

I have a map fragment within an activity. Simple. turn on Storage permission to allow display of Map,

3条回答
  •  终归单人心
    2021-02-20 07:46

    Probably a bit late, still might help out others in the future :)

    You should check to see if savedInstanceState is null which is passed to onCreate(Bundle savedInstanceState). If it's null only then, launch the Fragment like so:

    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_layout_file);
    
            if (savedInstanceState == null) {
                // do fragment transactions here
            }
        }
    

提交回复
热议问题