警报显示在每一天的Andr​​oid首家推出应用程序 [英] Show alert on first launch application of each day in android

查看:118
本文介绍了警报显示在每一天的Andr​​oid首家推出应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Android应用程序中,我被困在一个点上,

I am developing Android app in which i got stuck at one point,

我想要做的是,

当用户启动的第一次在一天的应用程序,我想告诉他一些警示。而当他打开一个应用程序,第二次在同一天也不会得到警报。 (他会得到一个警告仅在一天首家推出应用程序的)。

When user launches the app for the first time in a day, i want to show him a some alert. And when he opens a app for the second time in same day it will not get an alert. (he will get an alert only for the first launch of app in day).

第二天再次,如果他打开的第一次应用程序再次,他将得到警报,并在第二次,他不会得到警报。

next day again if he opens the app for the first time again he will get alert and on second time he will not get an alert.

在短:用户应该在第一次推出的每一天的警报

In short: User should get alert on first launch of each day.

任何想法,我应该如何实现这一目标?先谢谢了。

Any idea, how should i achieve this ? Thanks in advance.

推荐答案

我们可以通过的共享preference 。 在您的第一项活动,有其执行以下操作一步一步oncreatemethod的方法:

We can achieve this via a shared preference. In your first activity, have a method which does the following step by step in oncreatemethod:

1. Read a value (lastlaunchdate) from shared preference.

2. Check if current date = lastlaunchdate

3. If #2 is true, then ignore and proceed with usual flow

4. If #2 is false, then  

 4.a display the alert box

  4.b save current date as lastlaunchdate in shared preference.

样品code:

Sample code:

if (sharedPref.loadSharedPreference(getApplicationContext(), "LAST_LAUNCH_DATE").equals(new SimpleDateFormat("yyyy/MM/dd", Locale.US).format(new Date())))
{
    // Date matches. User has already Launched the app once today. So do nothing.
}
else
{
    // Display dialog text here......
    // Do all other actions for first time launch in the day...
    // Set the last Launched date to today.
    sharedPref.saveSharedPreference(getApplicationContext(), "LAST_LAUNCH_DATE", new SimpleDateFormat("yyyy/MM/dd", Locale.US).format(new Date()));
}

这篇关于警报显示在每一天的Andr​​oid首家推出应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆