Activity和Intent应用。实现两个Activity的跳转和两个Activity之间数据传输
package com.example.test_user_pw;
import android.os.Bundle;
import android.app.Activity;
import android.os.Bundle;
import android.preference.Preference;
import android.app.Activity;
import android.app.SearchManager.OnCancelListener;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;
import android.view.Menu;
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 Welcome extends Activity implements OnClickListener {
private EditText uname = null;
private EditText upswd = null;
private CheckBox checkboxButton = null;
private Button login = null;
SharedPreferences sp = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_main);
sp = this.getSharedPreferences("userinfo", Context.MODE_PRIVATE);
init();
}
public void init() {
uname = (EditText) findViewById(R.id.user_input);
upswd = (EditText) findViewById(R.id.pass_input);
checkboxButton = (CheckBox) findViewById(R.id.checkBoxLogin);
login = (Button) findViewById(R.id.new_user);
if (sp.getBoolean("checkboxBoolean", false)) {
uname.setText(sp.getString("uname", null));
upswd.setText(sp.getString("upswd", null));
checkboxButton.setChecked(true);
}
login.setOnClickListener(this);
}
@Override
public void onClick(View v) {
if (v == login) {
String name = uname.getText().toString();
String pswd = upswd.getText().toString();
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("uname", name);
editor.putString("upswd", pswd);
editor.putBoolean("checkboxBoolean", true);
editor.commit();
} else {
Editor editor = sp.edit();
editor.putString("uname", null);
editor.putString("upswd", null);
editor.putBoolean("checkboxBoolean", false);
editor.commit();
}
// Intent跳转
if (name.trim().equals("wang")&&pswd.trim().equals("123")) {
Intent intent = new Intent(Welcome.this, Content.class);
intent.putExtra("Stname", name.trim());
startActivity(intent);
finish();
}
else{
Toast.makeText(this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
return;
}
}
}
}
资源文件列表
Test_User_PW/.classpath , 475
Test_User_PW/.settings/org.eclipse.jdt.core.prefs , 177
Test_User_PW/AndroidManifest.xml , 1221
Test_User_PW/bin/AndroidManifest.xml , 1221
Test_User_PW/bin/Test_User_PW.apk , 373562
Test_User_PW/bin/classes/com/example/test_user_pw/Welcome.class , 3693
Test_User_PW/bin/classes/com/example/test_user_pw/MainActivity.class , 757
Test_User_PW/bin/classes/com/example/test_user_pw/Content.class , 832
Test_User_PW/bin/classes/com/example/test_user_pw/R$id.class , 694
Test_User_PW/bin/classes/com/example/test_user_pw/R$menu.class , 468
Test_User_PW/bin/classes/com/example/test_user_pw/R$string.class , 782
Test_User_PW/bin/classes/com/example/test_user_pw/R.class , 733
Test_User_PW/bin/classes/com/example/test_user_pw/R$style.class , 449
Test_User_PW/bin/classes/com/example/test_user_pw/R$layout.class , 487
Test_User_PW/bin/classes/com/example/test_user_pw/R$attr.class , 358
Test_User_PW/bin/classes/com/example/test_user_pw/R$drawable.class , 455
Test_User_PW/bin/classes/com/example/test_user_pw/R$dimen.class , 479
Test_User_PW/bin/classes/com/example/test_user_pw/BuildConfig.class , 357
Test_User_PW/bin/classes.dex , 690904
Test_User_PW/bin/dexedLibs/android-support-v4-bd83ca1c99e7a439e093a246986f7d4a.jar , 232610
Test_User_PW/bin/dexedLibs/android-support-v4-bccacee506845f9b79ad6705cb830226.jar , 232610
Test_User_PW/bin/jarlist.cache , 120
Test_User_PW/bin/res/crunch/drawable-mdpi/ic_launcher.png , 3112
Test_User_PW/bin/res/crunch/drawable-xhdpi/ic_launcher.png , 9355
Test_User_PW/bin/res/crunch/drawable-xxhdpi/ic_launcher.png , 17889
Test_User_PW/bin/resources.ap_ , 38365
Test_User_PW/bin/Copy of Test_User_PW.apk , 276993
Test_User_PW/gen/com/example/test_user_pw/BuildConfig.java , 166
Test_User_PW/gen/com/example/test_user_pw/R.java , 3694
Test_User_PW/ic_launcher-web.png , 51394
Test_User_PW/libs/android-support-v4.jar , 621451
Test_User_PW/proguard-project.txt , 781
Test_User_PW/project.properties , 563
Test_User_PW/res/drawable/btn_bg.xml , 343
Test_User_PW/res/drawable-mdpi/ic_launcher.png , 3777
Test_User_PW/res/drawable-xhdpi/ic_launcher.png , 12516
Test_User_PW/res/drawable-xxhdpi/ic_launcher.png , 24777
Test_User_PW/res/layout/activity_main.xml , 666
Test_User_PW/res/layout/content.xml , 702
Test_User_PW/res/layout/layout_main.xml , 2284
Test_User_PW/res/menu/content.xml , 263
Test_User_PW/res/menu/main.xml , 263
Test_User_PW/res/menu/welcome.xml , 263
Test_User_PW/res/values/dimens.xml , 220
Test_User_PW/res/values/strings.xml , 633
Test_User_PW/res/values/styles.xml , 697
Test_User_PW/res/values-sw600dp/dimens.xml , 203
Test_User_PW/res/values-sw720dp-land/dimens.xml , 277
Test_User_PW/res/values-v11/styles.xml , 334
Test_User_PW/res/values-v14/styles.xml , 391
Test_User_PW/src/com/example/test_user_pw/Content.java , 663
Test_User_PW/src/com/example/test_user_pw/MainActivity.java , 425
Test_User_PW/src/com/example/test_user_pw/Welcome.java , 2837
Test_User_PW/.project , 856
