android SharedPreferences实现用户的注册和保存账号密码

本文介绍了在Android开发中如何利用SharedPreferences进行用户注册和保存账号密码的操作。SharedPreferences采用键值对的方式存储数据,以XML文件形式保存在应用的私有目录下,适用于存储简单配置信息。通过示例代码展示了注册功能和用户名密码的持久化过程。
摘要由CSDN通过智能技术生成

在android开发中,我们做用户登录和注册的时候需要将用户名和密码保存,下次打开的时候记住应户名和密码。关于注册保存用户密码的方式和记住用户名和密码的保存方式有多种,这里介绍SharaedPreferenses保存方式。SharaedPreferenses是使用键值对的方式来存储数据的,它的本质是基于XML文件存储key-value键值对数据,通常用来存储一些简单的配置信息。其存储位置在/data/data/<包名>/shared_prefs目录下。

下面就通过一个小例子来实现这两项功能

1、注册的功能

布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".RegisteActivity" >

    <TableLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1">
        <TableRow >
        <TextView
            android:layout_height="wrap_content"
            android:text="账号:"/>
        <EditText 
            android:id="@+id/account"
            android:layout_height="wrap_content"
            android:hint="请输入您的账号"/>
    </TableRow>
    <TableRow >
        <TextView
            android:layout_height="wrap_content"
            android:text="密码:"/>
        <EditText 
            android:id="@+id/passeord"
            android:layout_height="wrap_content"
            android:inputType="textPassword"/>
    </TableRow>
    </TableLayout>
 
  • 7
    点赞
  • 64
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值