2011-03-23 53 views

回答

18

有幾種方法可以做到這一點,但也許最簡單的方法就是檢查SharedPreferences對象中的標誌,並在顯示警報時進行設置。

SharedPreferences

喜歡的東西

public class MyActivity extends Activity { 

public static final String PREFS_NAME = "MyPrefsFile"; 

@Override 
protected void onCreate(Bundle state){ 

    super.onCreate(state); 
    SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); 
    boolean dialogShown = settings.getBoolean("dialogShown", false); 

    if (!dialogShown) { 
    // AlertDialog code here 

    SharedPreferences.Editor editor = settings.edit(); 
    editor.putBoolean("dialogShown", true); 
    editor.commit();  
    } 
} 
相關問題