Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid Android automatically re-add my fragment on orientation change

I have a ListFragment which depends on the hosting Activity to properly initialize. On first run, it loads up fine. Once I change the orientation, my app crashes. From the stack trace I can see it isn't me trying to add the Fragment prematurely, rather Android is trying to restore the Fragment.

I have setRetainInstance(false) set in the onStart method but can't find any method to disable the restoring of the Fragment once the orientation changes. Any ideas? Do I need to remove the Fragment prior to my app being destroyed?

Edit: I ended up delaying initializing the list until the Activity is ready. Android conveniently shows a 'loading' message until the adapter is set.

like image 654
Al. Avatar asked Nov 15 '22 01:11

Al.


1 Answers

I ended up delaying initializing the list until the Activity is ready. Android conveniently shows a 'loading' message until the adapter is set.

like image 110
Al. Avatar answered Dec 09 '22 16:12

Al.