我正在我的应用程序中创建登录。用户输入他的信息,我将其发送到网络服务以检查并获取他的 ID。现在我需要将它保存在我的应用程序中的某个位置,以便我可以检查他是否已登录。
那么这些信息应该保存在哪里?我知道每个应用程序都有它的设置,所以应该有这个信息?也许有人可以给我更多信息这是什么以及如何做。
谢谢。
我发现了这个帖子: What is the most appropriate way to store user settings in Android application
我相信我的问题是重复的。但是如果你有更多的东西可以分享,那就太好了。
最佳答案
首先使用此代码在 SharedPreferences 中保存用户信息,例如 uname 和密码。
SharedPreferences settings = getSharedPreferences("UserInfo", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("Username",txtUname.getText().toString());
editor.putString("Password",txtPWD.getText().toString());
editor.commit();
然后从下面的代码中获取 SharedPreferences
SharedPreferences settings = getSharedPreferences("UserInfo", 0);
txtUname.setText(settings.getString("Username", "").toString());
txtPWD.setText(settings.getString("Password", "").toString());
关于android - 在应用设置中保存用户信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10209814/