赞
踩
-
- public class FirstFragment extends Fragment {
-
- static RxDataStore<Preferences> dataStore;
-
- public static RxDataStore<Preferences> SettingDataStore() {
- return dataStore;
- }
-
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- dataStore = new RxPreferenceDataStoreBuilder(getContext(), "setting").build();
- }
-
- public View onCreateView(
- LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState
- ) {
-
- Preferences.Key<String> CHOOSED_NOTE=PreferencesKeys.stringKey("CHOOSED_NOTE");
- Flowable<String> chooseNote= dataStore.data().map(prefs -> prefs.get(CHOOSED_NOTE));
- // 调用
- choose_note= chooseNote.blockingFirst();
-
- }catch (Exception e){
- }
-
-
- }

-
-
- public class SecondFragment extends DialogFragment {
-
- @Nullable
- @Override
- public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
-
- RxDataStore<Preferences> dataStore = SettingDataStore();
- Preferences.Key<String> CHOOSED_NOTE = PreferencesKeys.stringKey("CHOOSED_NOTE");
-
- //设置
- Single<Preferences> updateResult = dataStore.updateDataAsync(prefsIn -> {
- MutablePreferences mutablePreferences = prefsIn.toMutablePreferences();
- mutablePreferences.set(CHOOSED_NOTE, clickPath);
-
- return Single.just(mutablePreferences);
- });
-
-
- return view;
- }
-
-
-

赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。