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

时间:2023-03-09 12:52:16
判断用户是否是第一次打开该app
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(); }
}