android 引导界面的实现
现在越来越多程序都有引导页面了。
网上资料不全。现在自己实现下。
下图是总的目录结构。
/**
* 实现
* @author dujinyang
*
*/
顺序是: OneAcitivity -->MainActivity -> TwoActivity
然后第2次进去就是:OneActivity -> TwoActivity
代码里都有注释的了,这里就不多说了。
OneActivity的代码如下:
[java]
package cn.djy.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
/**
* 开机动画
* @author Administrator
*
*/
public class OneActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.one);
boolean flag=this.isFirstEnter(getApplicationContext(), this.getClass().getName());
if(flag)
mHandler.sendEmptyMessageDelayed(SWITCH_GUIDACTIVITY,4000);
else
mHandler.sendEmptyMessageDelayed(SWITCH_TWOACTIVITY, 4000);
}
//***********************************************************************
//判断应用是否初次加载,读取SharedPreferences 的字段
//***********************************************************************
private static final String SHAREDPREFERENCES_NAME="yang";
private static final String KEY_GUIDE_ACTIVITY="Open";
/**
* mResultStr.equalsIgnoreCase("false") 返回FALSE
* TRUE 则为空值
* @param context
* @param className
* @return boolean
*/
private boolean isFirstEnter(Context context,String className){
if(context==null || className ==null || "".equalsIgnoreCase(className)) return false;
String mResultStr=context.getSharedPreferences(SHAREDPREFERENCES_NAME,Context.MODE_WORLD_READABLE).getString(KEY_GUIDE_ACTIVITY, "");
if(mResultStr.equalsIgnoreCase("false"))
return false;
else
return true;
}
//****************************************
//Handler:跳转至不同页面
//****************************************
private final static int SWITCH_TWOACTIVITY=1000; //主页
private final static int SWITCH_GUIDACTIVITY=1001; //滑动手势
private Handler mHandler=new Handler(){
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case SWITCH_TWOACTIVITY:
Intent intent=new Intent();
intent.setClass(OneActivity.this,TwoActivity.class);
OneActivity.this.startActivity(intent);
// OneActivity.this.finish();
break;
case SWITCH_GUIDACTIVITY:
Intent intents=new Intent();
intents.setClass(OneActivity.this,MainActivity.class);
OneActivity.this.startActivity(intents);
// OneActivity.this.finish();
break;
}
super.handleMessage(msg);
};
};
}
package cn.djy.activity;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
/**
* 开机动画
* @author Administrator
*
*/
public class OneActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.one);
boolean flag=this.isFirstEnter(getApplicationContext(), this.getClass().getName());
if(flag)
mHandler.sendEmptyMessageDelayed(SWITCH_GUIDACTIVITY,4000);
else
mHandler.sendEmptyMessageDelayed(SWITCH_TWOACTIVITY, 4000);
}
//***********************************************************************
//判断应用是否初次加载,读取SharedPreferences 的字段
//***********************************************************************
private stat
补充:移动开发 , Android ,