我对android编程完全陌生。我正在做一个简单的应用程序,在其中显示启动屏幕,然后显示登录屏幕。问题是模拟器没有超出启动画面。安卓清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sanginfo.loginsample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.loginsample.LOGINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
登录活动:
package com.sanginfo.loginsample;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Patterns;
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 LoginActivity extends Activity {
CharSequence userName;
String passWord;
Boolean rememberme;
EditText username, password;
CheckBox tempchkrememberme;
Button login;
private SharedPreferences objSP;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* if(objSP.getString("username", null) != null) {*/
setContentView(R.layout.activity_login);
// UI elements gets bind in form of Java Objects
username = (EditText)findViewById(R.id.username);
password = (EditText)findViewById(R.id.password);
login = (Button)findViewById(R.id.login);
tempchkrememberme = (CheckBox)findViewById(R.id.chkrememberme);
objSP = this.getSharedPreferences("SharedPreferences", MODE_PRIVATE);
SharedPreferences.Editor objEditor = objSP.edit();
rememberme = objSP.getBoolean("rememberme", false);
if (rememberme == true){
username.setText(objSP.getString("username", ""));
tempchkrememberme.setChecked(true);}
//objEditor.putString("password", password.getText().toString());
objEditor.commit();
// now we have got the handle over the UI widgets
// setting listener on Login Button
// i.e. OnClick Event
login.setOnClickListener(loginListener);
}
//}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.login, menu);
return true;
}
private OnClickListener loginListener = new OnClickListener() {
public void onClick(View v) {
SharedPreferences.Editor objEditor = objSP.edit();
//getting inputs from user and performing data operations
userName=username.getText().toString();
String strUsername = username.getText().toString();
username = (EditText)findViewById(R.id.username);
password = (EditText)findViewById(R.id.password);
login = (Button)findViewById(R.id.login);
tempchkrememberme = (CheckBox)findViewById(R.id.chkrememberme);
if (userName.length()==0) {
username.requestFocus();
username.setError("Email is required.");
return;
}
boolean isEmailValid = Patterns.EMAIL_ADDRESS.matcher(userName).matches();
if (isEmailValid==false){
username.requestFocus();
username.setError("Email invalid.");
return;
}
if(password.getText().toString().length() == 0 ){
password.requestFocus();
password.setError( "Password is required." );
return;
}
if (tempchkrememberme.isChecked()) {
objEditor.putBoolean("rememberme", true);
objEditor.putString("username", strUsername);
//objEditor.putString("password", password);
objEditor.commit();
} else {
objEditor.clear();
objEditor.commit();
}
if(username.getText().toString().equals("aditya@sanginfo.com") &&
password.getText().toString().equals("password")){
// responding to the User inputs
Toast.makeText(getApplicationContext(), "Login Successful!", Toast.LENGTH_LONG).show();
}else
Toast.makeText(getApplicationContext(), "Invalid Credentials!", Toast.LENGTH_LONG).show();
}
};
}
飞溅类:
package com.sanginfo.loginsample;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void Run(){
try{
sleep(2000);
}
catch (InterruptedException ex){
ex.printStackTrace();
}
finally{
Intent openLoginActivity = new Intent(Splash.this, LoginActivity.class);
startActivity(openLoginActivity);
}
}
};
timer.start();
}
}
编辑:控制台:
[2013-09-24 15:02:58 - LoginSample] Android Launch!
[2013-09-24 15:02:58 - LoginSample] adb is running normally.
[2013-09-24 15:02:58 - LoginSample] Performing com.sanginfo.loginsample.Splash activity launch
[2013-09-24 15:02:58 - LoginSample] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'Nexus4'
[2013-09-24 15:03:00 - LoginSample] Application already deployed. No need to reinstall.
[2013-09-24 15:03:00 - LoginSample] Starting activity com.sanginfo.loginsample.Splash on device emulator-5554
[2013-09-24 15:03:01 - LoginSample] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.sanginfo.loginsample/.Splash }
[2013-09-24 15:03:01 - LoginSample] ActivityManager: Warning: Activity not started, its current task has been brought to the front
最后两个是红色的。
LogCat:(所有 E 为红色)
.....
09-24 14:16:37.892: I/System.out(904): Sending WAIT chunk
09-24 14:16:38.122: I/dalvikvm(904): Debugger is active
09-24 14:16:38.142: I/System.out(904): Debugger has connected
09-24 14:16:38.152: I/System.out(904): waiting for debugger to settle...
09-24 14:16:38.352: I/System.out(904): waiting for debugger to settle...
09-24 14:16:38.552: I/System.out(904): waiting for debugger to settle...
09-24 14:16:38.752: I/System.out(904): waiting for debugger to settle...
09-24 14:16:38.962: I/System.out(904): waiting for debugger to settle...
09-24 14:16:39.162: I/System.out(904): waiting for debugger to settle...
09-24 14:16:39.362: I/System.out(904): waiting for debugger to settle...
09-24 14:16:39.562: I/System.out(904): waiting for debugger to settle...
09-24 14:16:39.762: I/System.out(904): waiting for debugger to settle...
09-24 14:16:39.963: I/System.out(904): waiting for debugger to settle...
09-24 14:16:40.172: I/System.out(904): waiting for debugger to settle...
09-24 14:16:40.373: I/System.out(904): debugger has settled (1416)
09-24 14:16:42.502: D/gralloc_goldfish(904): Emulator without GPU emulation detected.
09-24 14:19:11.183: E/Trace(976): error opening trace file: No such file or directory (2)
09-24 14:19:12.423: D/gralloc_goldfish(976): Emulator without GPU emulation detected.
09-24 14:24:00.873: E/Trace(1024): error opening trace file: No such file or directory (2)
09-24 14:24:02.053: D/gralloc_goldfish(1024): Emulator without GPU emulation detected.
09-24 14:30:40.193: E/Trace(1070): error opening trace file: No such file or directory (2)
09-24 14:30:41.653: D/gralloc_goldfish(1070): Emulator without GPU emulation detected.
09-24 14:35:43.943: E/Trace(1117): error opening trace file: No such file or directory (2)
09-24 14:35:45.383: D/gralloc_goldfish(1117): Emulator without GPU emulation detected.
09-24 14:38:58.883: E/Trace(1191): error opening trace file: No such file or directory (2)
09-24 14:39:00.453: D/gralloc_goldfish(1191): Emulator without GPU emulation detected.
09-24 14:40:25.943: E/Trace(1237): error opening trace file: No such file or directory (2)
09-24 14:40:27.145: D/gralloc_goldfish(1237): Emulator without GPU emulation detected.
09-24 14:43:52.323: E/Trace(1309): error opening trace file: No such file or directory (2)
09-24 14:43:53.143: D/gralloc_goldfish(1309): Emulator without GPU emulation detected.
09-24 14:54:02.202: E/Trace(1358): error opening trace file: No such file or directory (2)
09-24 14:54:03.993: D/gralloc_goldfish(1358): Emulator without GPU emulation detected.