如何在Android本地保存登录信息 [英] How to save login Information locally in android

查看:76
本文介绍了如何在Android本地保存登录信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个运行良好的android应用.我在其中实现了登录功能.谁能指导我如何存储用户的登录凭据,以便用户不必在每次启动应用程序时以及登录用户时都注销,然后清除存储的登录信息.

I have made an android app which working fine. I implemented the Login functionality in it. Can anyone guide me how to store the login credentials of the user so that the user does not have to login everytime he/she starts the app and when user logout then clear the stored login information.

实际上,我希望用户不必每次启动应用程序时都输入登录信息.我该怎么办?

Actually i want that user does not have to enter login information everytime when he/she starts the app.How can i do this?

推荐答案

存储值使用sharepreference.我在这里粘贴代码..使用它.

Store value use sharepreference. i am pasting code here..use it.

创建共享首选项:

SharedPreferences sp=getSharedPreferences("Login", MODE_PRIVATE);
SharedPreferences.Editor Ed=sp.edit();
Ed.putString("Unm",Value );              
Ed.putString("Psw",Value);   
Ed.commit();

从共享"首选项中获取价值:

SharedPreferences sp1=this.getSharedPreferences("Login", MODE_PRIVATE);

String unm=sp1.getString("Unm", null);       
String pass = sp1.getString("Psw", null);

当用户注销时,您可以将null值设置为sharedpreference.

When user logout then you can set null value into sharedpreference.

这篇关于如何在Android本地保存登录信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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