我想創建一些需要在第一次獲取信息並保存它。該應用程序從MainActivity開始,如果它沒有所需的信息,應用程序會將您發送到MotoActivity。一旦應用程序有了這些信息,你就不需要再去MotoActivity了。我知道我錯了,但我不知道該怎麼做。SharedPreferences登錄
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences sp = getSharedPreferences("your_prefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putInt("valid", 0);
editor.commit();
int n = sp.getInt("valid", -1);
if(n == 0){
editor.putInt("valid", 1);
editor.commit();
startActivity(new Intent(MainActivity.this, MotoActivity.class));
MainActivity.this.finish();
}
謝謝!有效! – 2015-04-05 13:44:17
如果有幫助,您可以將我的答案設置爲正確答案;) – 2015-04-05 13:49:12