2011-05-04 41 views
1

如何在设备上安装我的Android应用程序后,我的对话框才会出现一次?想要在应用程序安装后仅显示一次对话框

+1

可能重复http://stackoverflow.com/questions/ 5409595 /我该如何显示警报对话框 - 仅限于我的应用程序的首次运行) – 2011-05-25 13:26:41

回答

9

使用SharedPreference存储firstrun值,并根据该值检查启动活动。如果设置了该值,则不需要显示对话框。否则,显示对话框并将SharedPreference中的firstrun标志保存。

前(在你的发射活动):

public void onCreate(){ 
    boolean firstrun = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getBoolean("firstrun", true); 
    if (firstrun){ 
     //... Display the dialog message here ... 
     // Save the state 
     getSharedPreferences("PREFERENCE", MODE_PRIVATE) 
      .edit() 
      .putBoolean("firstrun", false) 
      .commit(); 
    } 
} 
的[?我怎么只显示在我的应用程序第一次运行一个警告对话框(
+0

在末尾使用'getSharedPreferences'并带有S – DoubleYo 2013-03-22 13:09:08

相关问题