简体   繁体   中英

How to maintain binding on Fragment -> Intent -> Back to Fragment

I am using a Fragment and within my Fragment, I am starting a new Intent to access the device's settings. When I select the 'Back' button from the Android device, my bindings do not reflect in my View. The ViewModel properties are correct when I debug but the View doesn't reflect live data updates anymore. This only happens when I open the Intent

I am opening the Intent here:

private View.OnClickListener listener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
       Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
       startActivity(intent);
    }
};

I am using the ObservableFields in my ViewModel so I think it's working correctly as I mentioned before - the data is correct on the debugger, just not reflected in the View if I go into the Intent . The View will reflect any changes if I do not go into the Intent . Do I need to Override the onResume method ?

As the doc says,

the fields should be declared final in your data model because bindings only detect changes in the field's value, not of the field itself

Please check this statement. If if didn't fix your problem, can you post some additionnal code as your data model class, and how you use it in your fragment?

Hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM