Updating Screen Shards in ViewPager

I have an application with three fragments: Records, Chart, and PieChart. These fragments are stored in the ViewPager in one action, and the user can navigate between them. The record fragment has a table in which the user can enter data. When a user enters data, the other two pieces need to be updated as they refer to that data. I originally wanted the fragments to be updated as they scroll, but since they are executed using swipeable, I cannot use onPause () and onResume (), because onPause () (and therefore onResume ()) is only called, when the tab is 2+ screens. So I decided that the record fragment would send a callback to Activity to tell the other fragment to update itself when the record fragment was updated. I keep all the fragments in memory, and this works fine until the application goes into the background. When the application exits the background mode, if the user enters data into the table, the application crashes because all the variables in the remaining fragments are zero. Why is this happening? I do not use saveinstancestate anywhere in my application. Should I be?

+1
source share
1 answer

Following the example given here:

http://developer.android.com/reference/android/app/Fragment.html

You must save all of your data that supports each of your user interface components in the Bundle of your onSaveInstance () of your fragment. Then, in the onActivityCreated () callback, restore the data.

0
source

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


All Articles