package com.example.application;
import actionmovie.LoginActivity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView welcomeImg = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
welcomeImg = (ImageView) this.findViewById(R.id.welcome_img);
AlphaAnimation anima = new AlphaAnimation(0.3f, 1.0f);
anima.setDuration(3000);// 设置动画显示时间
welcomeImg.startAnimation(anima);
anima.setAnimationListener(new AnimationImpl());
}
private class AnimationImpl implements AnimationListener {
@Override
public void onAnimationStart(Animation animation) {
welcomeImg.setBackgroundResource(R.drawable.boot_0000);
}
@Override
public void onAnimationEnd(Animation animation) {
skip(); // 动画结束后跳转到别的页面
}
@Override
public void onAnimationRepeat(Animation animation) {
}
}
private void skip() {
startActivity(new Intent(MainActivity.this, LoginActivity.class));
finish();
}
}
上述是开机动画,要跳到 LoginActivity,动画结束后失败。
package actionmovie;
import com.example.application.BMainActivity;
import com.example.application.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
public class LoginActivity extends Activity implements OnClickListener {
private Button logbtn = null;
private EditText username = null;
private EditText password = null;
private String pswd, name;
private CheckBox checkboxButton = null;
SharedPreferences sp = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
init();
}
private void init() {
// TODO Auto-generated method stub
username = (EditText) findViewById(R.id.login_edit_account);
password = (EditText) findViewById(R.id.login_edit_pwd);
logbtn = (Button) findViewById(R.id.login_btn_login);
checkboxButton = (CheckBox) findViewById(R.id.Login_Remember);
if (sp.getBoolean("checkboxBoolean", false)) {
username.setText(sp.getString("username", null));
password.setText(sp.getString("password", null));
checkboxButton.setChecked(true);
}
logbtn.setOnClickListener(LoginActivity.this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
name = username.getText().toString().trim();
pswd = password.getText().toString().trim();
if (v == logbtn) {
if (name.equals("admin") && pswd.equals("123456")) {
if (name.trim().equals("")) {
Toast.makeText(this, "请您输入用户名!", Toast.LENGTH_SHORT).show();
return;
}
if (pswd.trim().equals("")) {
Toast.makeText(this, "请您输入密码!", Toast.LENGTH_SHORT).show();
return;
}
boolean CheckBoxLogin = checkboxButton.isChecked();
if (CheckBoxLogin) {
Editor editor = sp.edit();
editor.putString("username", name);
editor.putString("password", pswd);
editor.putBoolean("checkboxBoolean", true);
editor.commit();
} else {
Editor editor = sp.edit();
editor.putString("user", null);
editor.putString("pass", null);
editor.putBoolean("checkboxBoolean", false);
editor.commit();
}
Intent intent = new Intent();
intent.setClass(LoginActivity.this, BMainActivity.class);
startActivity(intent);
finish();
} else {
AlertDialog.Builder builder = new Builder(LoginActivity.this);
builder.setTitle(" 请确认!");
builder.setMessage(" 账号或密码错误");
builder.setPositiveButton("是", null);
builder.show();
}
}
}
}
两段代码,我一段段的切掉运行,发现在
if (sp.getBoolean("checkboxBoolean", false)) {
username.setText(sp.getString("username", null));
password.setText(sp.getString("password", null));
checkboxButton.setChecked(true);
}
缺少这个if语句是不会停止运行,且跳转成功,请问怎么解决啊。