不停地更改android通知消息并再次启动服务

当我在 android上启动Service时,这是我的通知方法
private void showNotification() {
        Notification notification = new Notification(R.drawable.call,"Some text",System.currentTimeMillis());
        Intent intent = new Intent(this,MainActivity.class);

        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pi = PendingIntent.getActivity(this,intent,0);
        notification.setLatestEventInfo(this,getString(R.string.notification_label),getString(R.string.notification_text_short),pi);
        notification.flags |= Notification.FLAG_NO_CLEAR;
        startForeground(7331,notification);
    }

以后可以更改文本吗?现在是例如“一些文本”,后来我想不停地更改它并再次启动服务.

那可能吗?

解决方法

您正在使用通知ID 7331显示通知以及启动服务.只要您发送具有相同ID的新通知,它就会替换旧的通知.

使用此选项更新通知

String ns = Context.NOTIFICATION_SERVICE;
notificationmanager mnotificationmanager = (notificationmanager) context
            .getSystemService(ns);
long when = System.currentTimeMillis();

Notification notification = new Notification("your icon","your ticker text",when);
/*<set your intents here>*/
mnotificationmanager.notify(7331,notification);

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...