一、BaseActivity繼承類
package com.favccxx.favdemo.base;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
public class BaseActivity extends Activity {
private static final String TAG = "BaseActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
android.util.Log.i(TAG, this.getClass().getSimpleName() + "onCreate Method is invoked!");
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
@Override
protected void onPostResume() {
// TODO Auto-generated method stub
super.onPostResume();
}
@Override
protected void onRestart() {
// TODO Auto-generated method stub
super.onRestart();
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onRestoreInstanceState(savedInstanceState);
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
protected void openActivity(Class<?> pClass) {
openActivity(pClass, null);
}
protected void openActivity(Class<?> pClass, Bundle pBundle) {
Intent intent = new Intent(this, pClass);
if (pBundle != null) {
intent.putExtras(pBundle);
}
startActivity(intent);
}
protected void openActivity(String pAction) {
openActivity(pAction, null);
}
protected void openActivity(String pAction, Bundle pBundle) {
Intent intent = new Intent(pAction);
if (pBundle != null) {
intent.putExtras(pBundle);
}
startActivity(intent);
}
}
二、SplashActivity
package com.favccxx.favdemo.ui;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import com.favccxx.favdemo.MainActivity;
import com.favccxx.favdemo.R;
import com.favccxx.favdemo.base.BaseActivity;
public class SplashActivity extends BaseActivity {
private Handler handler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = View.inflate(this, R.layout.activity_start, null);
setContentView(view);
Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha);
view.startAnimation(animation);
animation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
goBack();
}
}, 500);
}
});
}
@Override
protected void onResume() {
super.onResume();
}
private void goBack(){
openActivity(MainActivity.class);
finish();
}
}
三、activity_start.xml
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/splash_load">
</RelativeLayout>
四、AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.favccxx.favdemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.favccxx.favdemo.ui.SplashActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.favccxx.favdemo.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask"
android:screenOrientation="portrait"></activity>
</application>
</manifest>
目錄結構圖如下: