【问题标题】:how to save last entered edit text value in Android App?如何在 Android App 中保存最后输入的编辑文本值?
【发布时间】:2021-12-08 23:44:00
【问题描述】:

我正在创建一个简单的 android 应用程序,其中登录凭据作为编辑文本中的用户名和密码。 当用户尝试重新登录时,如何在应用程序中保存上次输入的用户名和密码。我该如何处理。我是否必须将它们存储在 android 应用程序中,或者它可以照顾我的 android。任何帮助将不胜感激。

<EditText
   android:id = "@+id/editText2"
   android:layout_width = "wrap_content"
   android:layout_height = "wrap_content"
   android:inputType = "textPassword" />

<EditText
   android:id = "@+id/editText1"
   android:layout_width = "wrap_content"
   android:layout_height = "wrap_content"
/>

【问题讨论】:

  • 可以尝试使用共享首选项,通过key=value保存值
  • 重新加载整个应用后是否会保存
  • 重新安装后 - 否,重新打开后 - 是

标签: android xml android-studio textview


【解决方案1】:

最简单的方法是使用Shared Preferences

但是存储原始凭据并不安全。

【讨论】:

    【解决方案2】:

    你可以用不同的方式做到这一点:

    • 将数据存储在本地Shared Preferences
    • 再次在本地保存数据,但使用 Room 等数据库。
    • 制作在线数据库并使用Retrofit或其他东西连接到它 像那样。 (当涉及到更大的项目时,这是一个不错的选择)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多