判断APP是不是第一次启动
基本思路就是,在第一次启动APP的时候,在本地保存一个布尔数据进行记录。如果是第一次启动保存为true,然后进行判断,如果是true,则提示是第一次启动并且修改为false。如果是false,则提示不是第一次启动。代码如下:MainActivity.javapackage f3.nsu.com.firststart; import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); firstRun(); } private void firstRun() { SharedPreferences sharedPreferences = getSharedPreferences("FirstRun",0); Boolean first_run = sharedPreferences.getBoolean("First",true); if (first_run){ sharedPreferences.edit().putBoolean("First",false).commit(); Toast.makeText(this,"第一次",Toast.LENGTH_LONG).show(); } else { Toast.makeText(this,"不是第一次",Toast.LENGTH_LONG).show(); } } }