【问题标题】:how to display notififcations one by one?如何一一显示通知?
【发布时间】:2011-07-16 10:22:08
【问题描述】:

他,我是android平台的新手。

现在我正在开发一个基于通知的小应用程序。

在我的应用程序中,每次显示通知时,我都会根据该时间维护一个计时器。

但问题是第一次显示通知,第二个通知附加在第一个通知上方,第三个通知附加在第二个通知上方........

我想一一显示通知。

如果有人知道如何一一显示通知。请回复我。

这是我的代码

myTimer = new Timer();
        myTimer.schedule(new TimerTask()
        {
        @Override
        public void run() 
        {

            TimerMethod();

        }

    }, 10000,10000);
}

private void TimerMethod()
{

    this.runOnUiThread(Timer_Tick);
}

private Runnable Timer_Tick = new Runnable()
{
    public void run()
     {


        mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        final Notification notifyDetails = new Notification(R.drawable.icon,"New Alert, Click Me!",System.currentTimeMillis());
        Context context = getApplicationContext();
        CharSequence contentTitle = "Notification Details...";
        CharSequence contentText = "you have a new notification find clicking me";
        Intent notifyIntent = new Intent(Notifi.this,Notifi.class);
        PendingIntent intent = 
            PendingIntent.getActivity(Notifi.this, 0, 
            notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
            notifyDetails.setLatestEventInfo(context, contentTitle, contentText, intent);
            mNotificationManager.notify(SIMPLE_NOTFICATION_ID, notifyDetails);






    }


};    

提前致谢

【问题讨论】:

    标签: android notifications


    【解决方案1】:

    在变量中存储固定的时间量,例如 5000 毫秒。

    现在,启动第一个通知并获取当前系统时间。为此添加 5000 毫秒并继续处理。在 5000 毫秒结束时关闭通知。如果第二个通知必须在第一个通知的 5 秒内显示,则使用 if 条件语句并检查自第一个通知开始时间起是否经过了 5000 毫秒。如果已经过去,则显示第二个,否则等到第一个完成。

    您还可以使用一个简单的标志检查是否有任何通知打开,该标志将在通知开始时设置为 1,在通知关闭时设置为 0。如果为0,则可以显示新的通知。

    [您也可以使用 2 个线程来执行此操作。在第一个线程上运行所有进程。第二个只是在开始后在设定的时间中断第一个。但是没试过这个]

    希望我能帮到你。

    【讨论】:

      猜你喜欢
      • 2017-09-22
      • 2023-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      相关资源
      最近更新 更多