应用程序启动3次后,Android显示弹出窗口

时间:2015-04-10 04:31:11

标签: java android performance android-intent android-activity

我想在我的应用中构建一个启动画面,只有在用户打开应用程序5次后才会显示,因此之后。

有谁知道我如何实现它?

2 个答案:

答案 0 :(得分:1)

-Hello您可以使用 Sharedpreferences

来完成

- 它背后的逻辑。在您的第一个启动器活动屏幕中,放置共享首选项并在其中放置 Int 变量,每次用户打开应用程序时将其增加+1并检查每次如果是3,则启动 SplashScreenActivity

- 有用的共享偏好代码: -

 SharedPreferences prefobj = getSharedPreferences(
                        "YourprefName", MODE_PRIVATE);

                Editor editor = prefobj.edit();
                editor.putInt("CheckInt", i);
                editor.commit();

- 以上代码用于每次添加你的int值增加

SharedPreferences Yourobj = getSharedPreferences("YourprefName",
            MODE_PRIVATE);
    int checkint = Yourobj.getInt("CheckInt", 0);

-TH将为您提供每次增加的变量值

-Thanks!

答案 1 :(得分:-1)

**Try this:**

在您的第一个活动的onCreate()中写下此

 if (isFifthTime()>=5)
                        {
                            Intent i = new Intent(this, SplashScreen.class);
                            startActivity(i);
                            finish();
                        }
                    else
                        {
  SharedPreferences sp =context.getSharedPreferences("yourPrefName", Activity.MODE_PRIVATE);
        int openedTimes = sp.getInt("checkInt",0);
        editor.putInt("checkInt", openedTimes+1);
        editor.apply();
            }


            public int isFifthTime()
                {
                    return getSharedPreferences("yourPrefName", Context.MODE_PRIVATE).getInt("checkInt", 0);
                }