判斷是否第一次登入
阿新 • • 發佈:2019-01-03
package text.xujiajian.asus.com.shaopdemo; import android.content.SharedPreferences; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SharedPreferences sp =this.getSharedPreferences("name",MODE_PRIVATE); boolean isFirst =sp.getBoolean("isFirst",true); SharedPreferences.Editor editor=sp.edit(); if(isFirst){ Log.i("", "onCreate: 第一次");editor.putBoolean("isFirst",false); editor.commit(); }else { Log.i("", "onCreate: 第二次"); } } }