gpt4 book ai didi

android - 在同一应用中不同 Activity 的调用之间保留文本字段上的数据

转载 作者:行者123 更新时间:2023-11-30 01:40:05 24 4
gpt4 key购买 nike

我有一个仍在构建的应用程序,该应用程序有 4 个 Activity 。数字 1 有 2 个文本字段。我调用其他 Activity ,例如 2,当调用 Activity 编号 1 时,在不破坏应用程序的情况下,我丢失了这些字段中的所有信息。如何保存这些数据。如果应用程序关闭(销毁),我不希望保留此数据。此数据不会与其他 Activity 共享。

最佳答案

你可以使用shared preference保存数据。

保存文本:

SharedPreferences.Editor editor = context.getSharedPreferences("GLOBAL_PREF", 0).edit();
editor.putString("text1", Value);
editor.commit();

获取文本:

String text1 = context.getSharedPreferences("GLOBAL_PREF", 0).getString("text1", null);

明确偏好:

SharedPreferences.Editor editor = context.getSharedPreferences("GLOBAL_PREF", 0).edit();
editor.clear();
editor.commit();

清除单键:

SharedPreferences.Editor editor = context.getSharedPreferences("GLOBAL_PREF", 0).edit();
editor.remove("text1");
editor.commit();

关于android - 在同一应用中不同 Activity 的调用之间保留文本字段上的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34603951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com