您的位置:首页 > 移动开发

判断用户是否是第一次打开该app

2017-04-19 14:33 316 查看
package com.example.fujilun_2;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;

public class LaunchActivity extends Activity{
//要保存的文件名
private final String SHARE_APP_TAG= "firstOpen";
private Boolean first;
private SharedPreferences setting;
@Override
protected void onCreate(Bundle savedInstanceState) {

// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_launch);

setting = getSharedPreferences(SHARE_APP_TAG, 0);
first = setting.getBoolean("FIRST",true);

new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}

if(first){
setting.edit().putBoolean("FIRST", false).commit();
Intent intent=new Intent(LaunchActivity.this,DemoActivity.class);
startActivity(intent);
finish();
}else{
Intent intent=new Intent(LaunchActivity.this,LoginActivity.class);
startActivity(intent);
finish();
}

}
}).start();

}
}


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: