2012-01-08 63 views

回答

15

您可以在您的應用程序SharedPreferences中設置一個特殊標誌(我們稱之爲firstRun)。如果沒有,這是第一次運行,所以請按照說明顯示您的活動/彈出窗口/任何內容,然後在首選項中設置firstRun

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    SharedPreferences settings = getSharedPreferences("prefs", 0); 
    boolean firstRun = settings.getBoolean("firstRun", true); 
    if (firstRun) 
    { 
     // here run your first-time instructions, for example : 
     startActivityForResult(
      new Intent(context, InstructionsActivity.class), 
      INSTRUCTIONS_CODE); 

    } 
} 



// when your InstructionsActivity ends, do not forget to set the firstRun boolean 
protected void onActivityResult(int requestCode, int resultCode, 
     Intent data) { 
    if (requestCode == INSTRUCTIONS_CODE) { 
     SharedPreferences settings = getSharedPreferences("prefs", 0); 
     SharedPreferences.Editor editor = settings.edit(); 
     editor.putBoolean("firstRun", false); 
     editor.commit(); 
    } 
} 
+2

它應該是:'editor.putBoolean( 「firstRun」,FALSE) ;'而不是'editor.putBoolean(「firstRun」,true);' – 70sCommander 2013-01-11 13:33:27

1

是的,你可以解決這個問題,SharedPreferences

SharedPreferences pref; 
SharedPreferences.Editor editor; 

pref = getSharedPreferences("firstrun", MODE_PRIVATE); 
editor = pref.edit(); 

editor.putString("chkRegi","true"); 
editor.commit(); 

然後檢查字符串chkRegi還是僞

相關問題