【问题标题】:How to create pop-up when first open app in Android?首次在 Android 中打开应用程序时如何创建弹出窗口?
【发布时间】:2016-03-19 03:59:21
【问题描述】:

我写了一个应用程序,我想获得一个电话号码,但getline1number() 在任何设备上都不起作用。

所以,我想创建一个弹出窗口来输入电话号码并提交以保存并且不会在下次打开应用程序中显示。

像这样:

【问题讨论】:

标签: android


【解决方案1】:

你总是可以使用SharedPreferences来做这样的事情:

SharedPreferences sp = getSharedPreferences("FirstTimeFile", Context.MODE_PRIVATE);

/**
 * when the app is opened for the first time, no such variable
 * (appIsOpenedForTheFirstTime) exists. So, it becomes true.
 */
boolean appIsOpenedForTheFirstTime = sp.getBoolean("IsAppOpenedForFirstTime",true);


//since it is true, it will be set to false after the execution of following block:
if(appIsOpenedForTheFirstTime) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putBoolean("IsAppOpenedForFirstTime", false);
    editor.commit();

    //PUT THE CODE FOR YOUR POPUP HERE
}

由于SharedPreferences 的值即使在您关闭应用程序后仍保留在应用程序数据中,因此下次打开应用程序时,appIsOpenedForTheFirstTime 的值将为 false,因此您的弹出代码不会执行。

啊,顺便说一句,如果您清除应用程序数据,所有内容都会被清除 - 包括 SharedPreferences。阅读this official article 以深入了解。

【讨论】:

    猜你喜欢
    • 2015-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 1970-01-01
    • 2014-07-04
    相关资源
    最近更新 更多