Notification 的 TransactionTooLargeException的问题

最近做一个需求,需要每隔五秒更新通知栏的ui,

考虑的性能问题,notification不是每次都new

然后再后台发现报了如下问题:

       android.os.TransactionTooLargeException
                                                            at android.os.BinderProxy.transactNative(Native Method)
                                                            at android.os.BinderProxy.transact(Binder.java:508)
                                                            at android.service.notification.INotificationListener$Stub$Proxy.onNotificationPosted(INotificationListener.java:167)
                                                            at com.android.server.notification.NotificationManagerService$NotificationListeners.notifyPosted(NotificationManagerService.java:3536)
                                                            at com.android.server.notification.NotificationManagerService$NotificationListeners.access$5800(NotificationManagerService.java:3342)
                                                            at com.android.server.notification.NotificationManagerService$NotificationListeners$2.run(NotificationManagerService.java:3450)
                                                            at android.os.Handler.handleCallback(Handler.java:815)
                                                            at android.os.Handler.dispatchMessage(Handler.java:104)
                                                            at android.os.Looper.loop(Looper.java:194)
                                                            at com.android.server.SystemServer.run(SystemServer.java:417)
                                                            at com.android.server.SystemServer.main(SystemServer.java:295)
                                                            at java.lang.reflect.Method.invoke(Native Method)
                                                            at java.lang.reflect.Method.invoke(Method.java:372)
                                                            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1119)
                                                            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)



查看 

setOnClickPendingIntent 的源码,发现
最终,系统是这么做的

 *
 * @param a The action to add
 */
private void addAction(Action a) {
    if (hasLandscapeAndPortraitLayouts()) {
        throw new RuntimeException("RemoteViews specifying separate landscape and portrait" +
                " layouts cannot be modified. Instead, fully configure the landscape and" +
                " portrait layouts individually before constructing the combined layout.");
    }
    if (mActions == null) {
        mActions = new ArrayList<Action>();
    }
    mActions.add(a);

    // update the memory usage stats
    a.updateMemoryUsageEstimate(mMemoryUsageCounter);
}

mActions  没有考虑到add的内容是否重复。。。

所以,如果重复
setOnClickPendingIntent  的话,就会产生上面的bug,

解决方案
===================》notification 复用了一百次()之后,选择丢弃,重新new 一个,


while (flag) {
    index++;
    if (index%100==0){
	//当到第一百次的时候重新init一个,之前的丢弃
        initNotification();
    }
    else {
        addNotificaiton();
    }
}




bug解决!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值