判断是否第一次进入应用

   判断是否第一次进入应用,以决定是否启动引导页。

   这个都用常规方法,使用SharePreference进行保存变量,然后每次进入应用时首先先检测变量的值,来决定是否启动引导页

 代码如下:

public class SplashActivity extends Activity {  
   
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        //setContentView(R.layout.activity_splash);  
           
        boolean mFirst = isFirstEnter(SplashActivity.this,SplashActivity.this.getClass().getName());  
        Toast.makeText(this, mFirst+"", Toast.LENGTH_SHORT).show();  
        if(mFirst)  
            mHandler.sendEmptyMessageDelayed(SWITCH_GUIDACTIVITY,100);  
        else  
            mHandler.sendEmptyMessageDelayed(SWITCH_MAINACTIVITY,100);  
        SharedPreferences sharedPreferences= this.getSharedPreferences("my_pref", MODE_PRIVATE);  
        sharedPreferences.edit().putString("guide_activity", "false").commit();  
          
          
    }     
       
    private static final String SHAREDPREFERENCES_NAME = "my_pref";  
    private static final String KEY_GUIDE_ACTIVITY = "guide_activity";  
    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, "");//取得所有类名 如 com.my.MainActivity  
        if(mResultStr.equalsIgnoreCase("false"))  
            return false;  
        else  
            return true;  
    }  
        
    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();  
                mIntent.setClass(SplashActivity.this, Welcome.class);  
                SplashActivity.this.startActivity(mIntent);  
                SplashActivity.this.finish();  
                break;  
            case SWITCH_GUIDACTIVITY:  
                mIntent = new Intent();  
                mIntent.setClass(SplashActivity.this, GuideActivity.class);  
                SplashActivity.this.startActivity(mIntent);  
                SplashActivity.this.finish();  
                break;  
            }  
            super.handleMessage(msg);  
        }  
    };  
}  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值