1、给Button设置监听器
2、当点下按钮时,设置Boolean的缓存数据
3、跳转到MainUI,结束自己
———————WelcomeUI.java—————————————
package huaxa.it.zhihuidemo;
import huaxa.it.zhihuidemoUtils.CacheUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
/**
* @项目名: ZhiHuiDemo
* @包名: huaxa.it.zhihuidemo
* @类名: WelcomeUI
* @创建者: 黄夏莲
* @创建时间: 2016年10月3日 ,上午10:52:21
*
* @描述: TODO
*/
public class WelcomeUI extends Activity
{
.....
protected void doJump()
{
// 页面跳转
// 根据情况进行页面跳转
// 如果是第一次打开应用程序,那么久进入引导页面,否则进入主页
Boolean isFirstStart = CacheUtils.getBoolean(this, KEY_FIRST_START,
true);
if (isFirstStart)
{
Log.d(TAG, "进入引导页面");
Intent intent = new Intent(this, GuideUI.class);
startActivity(intent);
} else
{
Log.d(TAG, "进入主页面");
Intent intent = new Intent(this,MainUI.class);
startActivity(intent);
}
finish();
}
}
mPager.setOnPageChangeListener(this);
public void onClick(View v)
{
// 设置点击事件
if(v == start_btn){
clickStart();
}
}
private void clickStart()
{
//设置已经开启过应用
CacheUtils.setBoolean(this,WelcomeUI.KEY_FIRST_START, false);
//页面跳转
Intent intent = new Intent(this,MainUI.class);
startActivity(intent);
//结束自己
finish();
}
package huaxa.it.zhihuidemoUtils;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
/**
* @项目名: ZhiHuiDemo
* @包名: huaxa.it.zhihuidemoUtils
* @类名: CacheUtils
* @创建者: 黄夏莲
* @创建时间: 2016年10月3日 ,下午6:09:45
*
* @描述:跳转页面
*
*/
public class CacheUtils
{
<span style="white-space:pre"> </span>private final static String<span style="white-space:pre"> </span>sharedPreferencesName<span style="white-space:pre"> </span>= "zhbj";
<span style="white-space:pre"> </span>private static SharedPreferences mpreferences;//静态的,从内存取(只需取1次),比读文件快(每次都要读取)
<span style="white-space:pre"> </span>private static SharedPreferences getsp(Context context){
<span style="white-space:pre"> </span>if(mpreferences == null){
<span style="white-space:pre"> </span>mpreferences = context.getSharedPreferences(
<span style="white-space:pre"> </span>sharedPreferencesName, Context.MODE_PRIVATE);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>return mpreferences;
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 通过sp获得boolean类型的数据,没有默认为false
<span style="white-space:pre"> </span> *
<span style="white-space:pre"> </span> * @param context
<span style="white-space:pre"> </span> * :上下文
<span style="white-space:pre"> </span> * @param key
<span style="white-space:pre"> </span> * :存储的key
<span style="white-space:pre"> </span> * @return
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>public static boolean getBoolean(Context context, String key)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>// TODO Auto-generated method stub
//<span style="white-space:pre"> </span>SharedPreferences mpreferences = context.getSharedPreferences(
//<span style="white-space:pre"> </span>sharedPreferencesName, Context.MODE_PRIVATE);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>mpreferences = getsp(context);
<span style="white-space:pre"> </span>return mpreferences.getBoolean(key, false);// 第二个参数为缺省值,如果preference中不存在该key,将返回缺省值
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> * 通过sp获得boolean类型的数据,没有默认为false
<span style="white-space:pre"> </span> *
<span style="white-space:pre"> </span> * @param context
<span style="white-space:pre"> </span> * :上下文
<span style="white-space:pre"> </span> * @param key
<span style="white-space:pre"> </span> * :存储的key
<span style="white-space:pre"> </span> * @param defValue
<span style="white-space:pre"> </span> * :默认值
<span style="white-space:pre"> </span> * @return
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>public static boolean getBoolean(Context context, String key,
<span style="white-space:pre"> </span>boolean defValue)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>// TODO Auto-generated method stub
//<span style="white-space:pre"> </span>SharedPreferences mpreferences = context.getSharedPreferences(
//<span style="white-space:pre"> </span>sharedPreferencesName, Context.MODE_PRIVATE);
<span style="white-space:pre"> </span>mpreferences = getsp(context);
<span style="white-space:pre"> </span>return mpreferences.getBoolean(key, defValue);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>/**
<span style="white-space:pre"> </span> *
<span style="white-space:pre"> </span> * 设置Boolean的缓存数据
<span style="white-space:pre"> </span> *
<span style="white-space:pre"> </span> * @param context
<span style="white-space:pre"> </span> * :上下文
<span style="white-space:pre"> </span> * @param key
<span style="white-space:pre"> </span> * :缓存对应的key
<span style="white-space:pre"> </span> * @param value
<span style="white-space:pre"> </span> * :缓存对应的值
<span style="white-space:pre"> </span> * @return
<span style="white-space:pre"> </span> */
<span style="white-space:pre"> </span>public static void setBoolean(Context context, String key, boolean value)
<span style="white-space:pre"> </span>{
//<span style="white-space:pre"> </span>SharedPreferences mpreferences = context.getSharedPreferences(
//<span style="white-space:pre"> </span>sharedPreferencesName, Context.MODE_PRIVATE);
<span style="white-space:pre"> </span>mpreferences = getsp(context);
<span style="white-space:pre"> </span>Editor editor = mpreferences.edit();// 获取编辑器
<span style="white-space:pre"> </span>editor.putBoolean(key, value);
<span style="white-space:pre"> </span>editor.commit();
<span style="white-space:pre"> </span>}
}
package huaxa.it.zhihuidemo;
import android.app.Activity;
import android.os.Bundle;
/**
* @项目名: ZhiHuiDemo
* @包名: huaxa.it.zhihuidemo
* @类名: MainUI
* @创建者: 黄夏莲
* @创建时间: 2016年10月4日 ,下午11:38:11
*
* @描述: 主页面
*/
public class MainUI extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
<activity
android:name=".MainUI"
android:label="@string/app_name" >
</activity>