点击后通知会消失然后重新出现?

时间:2015-06-10 13:56:30

标签: android

嗨,我有一个通知设置在特定的日期和时间。这是我的代码 -

private void createPushTimer() {
    // TODO Auto-generated method stub
    Calendar calendar = Calendar.getInstance();
    Intent intent = new Intent(MainActivity.this, Drawing.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 2, intent, 0);
    AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
    int day = calendar.get(Calendar.DAY_OF_WEEK);
    if (day == 4) { //5 is thurs
        calendar.set(Calendar.HOUR_OF_DAY, 9); 
        calendar.set(Calendar.MINUTE, 48);
        calendar.set(Calendar.SECOND, 0);
        am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY*7, pendingIntent);
    }
    //am.setRepeating(AlarmManager.RTC_WAKEUP, 10000, AlarmManager.INTERVAL_DAY, pendingIntent);
}

以下是通知的接收类 -

 public void showNotification(Context context) {
    Intent intent = new Intent(context, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(context, 0, intent, 1);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
        .setSmallIcon(R.drawable.ic_launcher)
        .setContentTitle("Drawing!")
        .setContentText("The new drawing has been updated! Check the new numbers!")
        .setAutoCancel(true);
    mBuilder.setContentIntent(pi);
    mBuilder.setDefaults(Notification.DEFAULT_SOUND);
    //mBuilder.setAutoCancel(true);
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mNotificationManager.notify(0, mBuilder.build());
}

它在适当的时间(周三9:48进行测试)但是当点击通知时,它会再次出现在应用程序的开头。它确实消失了一段时间但随后重新出现。即使是点击的时间。有没有更好的方法来做到这一点,还是我错过了什么?谢谢你的帮助。

0 个答案:

没有答案