I have a situation to update Bundle
value, like below:
我有更新Bundle值的情况,如下所示:
Bundle dataBundle = new Bundle();
dataBundle.putString("name",object.getString("name"));
dataBundle.putString("email",object.getString("email"));
dataBundle.putString("id",object.getString("_id"));
dataBundle.putString("otp",object.getString("otp"));
Now user can send the the request for re-otp, and i have to update otp
, is there any way to update?
现在用户可以发送re-otp的请求,我必须更新otp,有什么方法可以更新吗?
2 个解决方案
#1
2
You can update/override the bundle key value just setting the new value in same bundle coresponding to same key (It will don't affect on other key values of this bundle)
您可以更新/覆盖捆绑键值,只需在相同的捆绑中设置新值,对应相同的密钥(它不会影响此捆绑包的其他键值)
// This will update value of otp with "newotp" in dataBundle
dataBundle.putString("otp","newotp");
#2
1
Write to shared preferences because using shared preference will be easy to update and read the data.
写入共享首选项,因为使用共享首选项将很容易更新和读取数据。
Write & Update Data
写入和更新数据
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor. putString("otp", object.getString("otp"));
editor.commit();
Read Data
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
String otp= sharedPref.getString("otp", defaultValue);
#1
2
You can update/override the bundle key value just setting the new value in same bundle coresponding to same key (It will don't affect on other key values of this bundle)
您可以更新/覆盖捆绑键值,只需在相同的捆绑中设置新值,对应相同的密钥(它不会影响此捆绑包的其他键值)
// This will update value of otp with "newotp" in dataBundle
dataBundle.putString("otp","newotp");
#2
1
Write to shared preferences because using shared preference will be easy to update and read the data.
写入共享首选项,因为使用共享首选项将很容易更新和读取数据。
Write & Update Data
写入和更新数据
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor. putString("otp", object.getString("otp"));
editor.commit();
Read Data
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
String otp= sharedPref.getString("otp", defaultValue);