安卓笔记之《第一次运行程序进入引导页面的实现》

来源:互联网 发布:淘宝线上推广合同范本 编辑:程序博客网 时间:2024/05/21 14:55
package com.evecom.first;import android.app.Activity;import android.content.Intent;import android.content.SharedPreferences;import android.content.SharedPreferences.Editor;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.util.Log;import android.widget.Toast;public class SplashActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_splash);        //判断是否第一次运行        isFirstRun();    }    /**     * 判断是否第一次运行     * */    private void isFirstRun() {        SharedPreferences sharedPreferences = this.getSharedPreferences("share", MODE_PRIVATE);         boolean isFirstRun = sharedPreferences.getBoolean("isFirstRun", true);         Editor editor = sharedPreferences.edit();         if (isFirstRun){             Log.i("TAG", "第一次运行");             Toast.makeText(this, "第一次运行,将进入引导页面...", Toast.LENGTH_SHORT).show();            editor.putBoolean("isFirstRun", false); //第一次运行后,将isFirstRun赋值为false            editor.commit();             mHandler.sendEmptyMessageDelayed(SWITCH_GUIDACTIVITY, 3000);        } else{             Log.i("TAG", "不是第一次运行");             Toast.makeText(this, "不是第一次运行,将直接进入主页面...", Toast.LENGTH_SHORT).show();            mHandler.sendEmptyMessageDelayed(SWITCH_MAINACTIVITY, 3000);        }    }    /**     * Handler:跳转至不同页面     **/    private final static int SWITCH_MAINACTIVITY = 1000;    private final static int SWITCH_GUIDACTIVITY = 1001;    public Handler mHandler = new Handler(){        public void handleMessage(Message msg) {            switch(msg.what){            case SWITCH_MAINACTIVITY://进入主页面                Intent mIntent = new Intent(SplashActivity.this, MainActivity.class);                startActivity(mIntent);                finish();                break;            case SWITCH_GUIDACTIVITY://进入引导页面                mIntent = new Intent(SplashActivity.this, GuideActivity.class);                startActivity(mIntent);                finish();                break;            }            super.handleMessage(msg);        }    };}
0 0