Я передаю строку из действия во фрагмент, все работает отлично, но моя переданная строка не обновляется мгновенно, она обновляется после перезапуска моего приложения. Через поиск Google я попытался изменить свой код «editor.commit» на «editor.apply», но нет используйте, пожалуйста, помогите мне с вашими предложениями, спасибо
Activity.cs
var text = newSentence.ToString();
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor editor = prefs.Edit();
editor.PutString("Data", text);
editor.Apply();
editor.Clear();
Фрагмент.cs
public class Fragment1 : Android.Support.V4.App.Fragment
{
public string mString;
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(Android.App.Application.Context);
mString = prefs.GetString("Data", " ");
}
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate(Resource.Layout.Fragment1, container, false);
var textView = view.FindViewById<TextView>(Resource.Id.txtView);
textView.Text = mString;
return view;
}
}