我希望我的应用程序仅在应用程序第一次启动时启动活动。
有人知道吗?
我发现了这个,但它只显示黑屏。
public class WhatsNew extends Activity {
public static final String PREFS_NAME = "MyPrefsFile";
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();
}
}
}
当应用程序启动时,在活动首选项中设置该活动已运行的标志。默认设置为 false,然后仅在未设置该标志的情况下启动该活动。请注意,如果用户清理您的应用程序数据,或卸载它并稍后再次安装,则该活动将再次显示。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)