2011-03-23 22 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();  
    } 
} 
相关问题