1.判断用户有没有登录
<span >SharedPreferences sharedPreferences=getSharedPreferences("YUNCHAT", MODE_PRIVATE);
if(!sharedPreferences.contains("userName")){
new Thread(){
public void run(){
Intent intent=new Intent(MainActivity.this,LoginActivity.class);
startActivity(intent);
}
}.start();
}</span>
2.如果没有则登录
<span >btn_login.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
userName=username.getText().toString();
userPwd=password.getText().toString();
SharedPreferences sp=getSharedPreferences("YUNCHAT", MODE_PRIVATE);
Editor editor=sp.edit();
editor.putString("userName", userName);
editor.commit();
Intent intent=new Intent(LoginActivity.this,MainActivity.class);
startActivity(intent);
}
});</span>