Workaround for Android error related to setRetainInstance (true)

Please check out this issue: http://code.google.com/p/android/issues/detail?id=20791

The project (https://github.com/kaciula/BugRetain) uses CursorLoader to get two values ​​from the database through the content provider and display them on the screen. The scenario is this: from activity A, go to activity B, switch once to orientation and return to activity A. Values ​​from db are no longer displayed.

Can someone provide a workaround for this problem? The problem does not occur only with CursorLoader, but with any bootloader. As a consequence of this error, I cannot write an application with fragments that use setRetainInstance and are available in both orientations. I really need a workaround until the guys from Android fix the problem. Any ideas?

+4
source share
1 answer

Do not set your snippets as persistent if you use Loaders. If you need to save some data between configuration changes, create another saved fragment and transfer this data to it.

A similar example can be found here: FragmentRetainInstanceSupport . But this example uses an extra snippet for streaming purposes. In your case, this additional fragment will be used as a data container.

+4
source

Source: https://habr.com/ru/post/1386048/


All Articles