当前位置:网站首页>Sharepreference (storage)
Sharepreference (storage)
2022-07-27 19:52:00 【Ashurol】


public class MainActivity extends ActionBarActivity {
EditText et_yh;
EditText et_mm;
Button bt_dl;
Button bt_qx;
CheckBox cb;
SharedPreferences spf;
Editor editor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//SharedPreferences sp=PreferenceManager.getDefaultSharedPreferences(this);
// SharedPreferences sp=getSharedPreferences("mysp", MODE_PRIVATE);
// Editor editor=sp.edit();
// editor.putString("name", " Zhang San ");
// editor.putInt("age", 18);
// editor.putLong("time", System.currentTimeMillis());
// editor.putBoolean("default", true);
// editor.commit();
// editor.remove("time");
// editor.commit();
// System.out.println(sp.getString("name", ""));
// editor.commit();
et_yh=(EditText) findViewById(R.id.et_yonghu);
et_mm=(EditText) findViewById(R.id.et_mima);
cb=(CheckBox) findViewById(R.id.checkBox1);
spf=getSharedPreferences("UserInfo", MODE_PRIVATE);
editor=spf.edit();
String name=spf.getString("Username","");
Log.i("info", name);
if(name=="")
{
cb.setChecked(false);
}else{
cb.setChecked(true);
et_yh.setText(name);
}
}
public void doClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.button1:
String name=et_yh.getText().toString().trim();
String pass=et_mm.getText().toString().trim();
if("liuxin".equals(name)&&"123456".equals(pass))
{
if(cb.isChecked())
{
editor.putString("Username", name);
editor.commit();
}else{
editor.remove("Username");
editor.commit();
//Log.i("info", "22");
}
Toast.makeText(this, " Login successful ", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(this, " Login failed , Incorrect password or user name ", Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
}

Reopen after launching the program

边栏推荐
- [basic knowledge of deep learning - 37] solve the imbalance between positive and negative samples
- Optimization of fixed number of cycles in embedded C language
- 三星将推多款RISC-V架构芯片,5G毫米波射频芯片会率先采用
- Oracle 日期的转换
- mysql学习录(三)多表查询、子查询、分页查询、case语句、单行函数
- 5W bonus pool / for colleges and universities, 2022 legal science and technology innovation competition is in progress
- rxbinding
- DNSSEC verification with dig [verify DNSSEC with dig]
- 传苹果计划以2亿美元购买JDI部分工厂
- Map and set
猜你喜欢

Detailed explanation of the underlying data structure of redis

JVM概述和内存管理(未完待续)

ArrayAdapter(数组适配器)与SimpleAdapter(简单适配器)

vlan试验2021.1.14

下放三星3J1传感器:代码暗示Pixel 7人脸识别安全性将大增

Release Samsung 3J1 sensor: the code implies that the safety of pixel 7 face recognition will be greatly increased

Flink introduction and operation architecture

S32k series chips -- Introduction

VS2017#include 'xxx.h'

SQlife(数据库)
随机推荐
Transaction log full problem handling in sqlserver 2008
Intent(有无返回值得跳转)
Binary search tree
IIS 发生未知FastCGI错误:0x80070005
What's new in helix QAC 2022.2, the ace code static testing tool (2)
[basic knowledge of deep learning - 44] the method of realizing multiple classification by logistic regression
[basic knowledge of deep learning - 43] concept of odds ratio
Virtualbox:ssh connection
Hdu1573 x problem [univariate linear congruence equations]
JS find all nodes sibling childNodes children
ReferenceError: __ dirname is not defined in ES module scope
SQlife(数据库)
文件操作防护
【深度学习基础知识 - 47】贝叶斯网络与朴素贝叶斯
The valuation exceeds 15.6 billion yuan! Huaqin communication completed the round B financing of 1billion yuan! Qualcomm venture capital, Intel Capital led investment
BroadcastReceiver(广播)
贪心
Surpass Huawei? Ericsson has won more than 75 5g commercial contracts
【深度学习基础知识 - 43】优势比的概念
ContextMenu (context menu)