保存的Andr​​oid应用程序中的登录用户的详细信息 [英] Android save login user details in application

查看:152
本文介绍了保存的Andr​​oid应用程序中的登录用户的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Web开发人员和新来的Andr​​oid和研究...对于第一步,我用PHP MySQL的Web服务作出了用户登录系统。

I am a web developer and new to android and studying ... For first step I made an user login system using PHP-MySQL web services.

应用程序与Web服务pretty沟通好,并检查用户是否存在。现在,如果用户存在,如果用户存在,将返回用户的详细信息。

The application communicating with the web service pretty well and check for user exists. Now if the user exists it will return the user details if user exists.

我的问题,就像是Web应用程序中存在的Andr​​oid应用程序的任何会话/ cookie处理?对于例如,如果我能保存会话则不必每一次都在登录。

My question is like in web application is there any session / cookie handling in android application ? For eg if I can save the session then not need to login at each and every time.

我相信是有办法做到这一点,因为很多应用程序都使用该功能。但由于我是新至Android请指点一下。

I am sure there is a way to do this because lots of apps are working with this feature. But since I am new to android please advice a bit.

不知道正确的单词google搜索。是保存preferences。

Not knowing a correct word to googling. Is that "SavePreferences".

在此先感谢

推荐答案

我想你要找的是的共享preferences 的。这种存储持久数据的(键,值)对,所以你可以说有在登录屏幕上一个复选框,这样,如果他们选中它,然后它存储了布尔及其作为键的用户名。然后,当他们到达登录屏幕,并选择自己的用户名会检查该值,如果是真正则不需要密码。这是假设你允许多个用户从应用程序登录。

I think what you are looking for is SharedPreferences. This stores data persistently in a (key, value) pair so you could say have a check box at the login screen so if they check it then it stores a boolean as the value and their username as the key. Then when they get to the login screen and choose their username it checks that value and if it is true then it doesn't require a password. This is assuming that you allow more than one user to login from the app.

不过,如果你只有一个人从应用程序到该设备在登录,那么你可以从Web服务器上,当他们打开,他们可以跳过登录屏幕的应用程序返回一个值。

However, if you only have one person logging in from the app to that device, then you could send back a value from the web server when they open the app that they can skip the login screen.

除了链接到文档我上面提供的这是在文档一个很好的例子,让你开始

Besides the links to the docs I provided above, Here is a good example in the docs to get you started

如果您需要的东西比什么共享preferences提供了更强大的,然后看的存储选项的文档的部分。希望这有助于

If you are in need of something more robust than what SharedPreferences provides, then look at the Storage Options section of the docs. Hope this helps

找回preFS

SharedPreferences prefs = this.getSharedPreferences("john smith", 0);
    saved= (prefs.getString("loginSaved", false));  
if (saved)
  // do stuff here
else
  // require login

这篇关于保存的Andr​​oid应用程序中的登录用户的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆