android.widget.RemoteViews$ReflectionAction.writeToParcel(RemoteViews.java :763) 4.0.3和4.0.4版本
2014-12-01 18:33
316 查看
通知栏使用RemoteView是报的错
在给RemoteViews中的控件绑定相应的参数,比如给ImageView绑定图片资源id,TextView绑定字符串资源Id。
错误就是在绑定时出现的,而且有特定的情况:1.当你的Bitmap为null时
2.当你的String为 “” 或者null时
3.你的android版本是4.0.3,和4.0.4时
也就是说,如果你的通知栏是动态变化的,需要更新显示各种状态的,资源则是通过调用封装好的类来读取的,这时候就一定要注意了,返回的资源一定要判断是否为空,当然widget也用到了RemoteView同样需要注意。
如图:
点击more的时候可以更换更多的功能和app
如果你的android版本是4.1以上的,则不会出现上述的异常,读不到图片就是控件不显示图片而已,不会导致程序崩溃,在4.0.x的版本的小伙伴要格外的注意,这个bug我花了一天的时间测试出来的,排查起来有点费劲,4.0以下的没有用到就没有测试,如果有小伙伴测试了可以告知一下结果。
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.notify_black_layout)
在给RemoteViews中的控件绑定相应的参数,比如给ImageView绑定图片资源id,TextView绑定字符串资源Id。
remoteViews.setImageViewBitmap(R.id.imageview1,R.drawable.icon_launcher); remoteViews.setTextViewText(R.id.textview1,R.string.helloworld);
错误就是在绑定时出现的,而且有特定的情况:1.当你的Bitmap为null时
2.当你的String为 “” 或者null时
3.你的android版本是4.0.3,和4.0.4时
也就是说,如果你的通知栏是动态变化的,需要更新显示各种状态的,资源则是通过调用封装好的类来读取的,这时候就一定要注意了,返回的资源一定要判断是否为空,当然widget也用到了RemoteView同样需要注意。
如图:
点击more的时候可以更换更多的功能和app
如果你的android版本是4.1以上的,则不会出现上述的异常,读不到图片就是控件不显示图片而已,不会导致程序崩溃,在4.0.x的版本的小伙伴要格外的注意,这个bug我花了一天的时间测试出来的,排查起来有点费劲,4.0以下的没有用到就没有测试,如果有小伙伴测试了可以告知一下结果。
相关文章推荐
- android.widget.RemoteViews$ReflectionAction.writeToParcel(RemoteViews.java :763) 4.0.3和4.0.4版本
- java.lang.ClassCastException: android.app.ActionBar$LayoutParams cannot be cast to android.widget.Ab
- [Android笔记] 关于 AppWidget 动态更新:RemoteViews 更新缓慢&内存溢出
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.wid
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView解决办法
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- java.lang.ClassCastException: android.widget.HeaderViewListAdapter cannot be cast to com.android.mms
- java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.widget.L(转)
- java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w
- android中ADT版本问题: java.lang.NoClassDefFoundError和conversion to dalvik format failed with error 1错误
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.widg
- Caused by: java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.HEADSET_PLUG
- java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.wid
- java.lang.ClassCastException: 。。。$LayoutParams cannot be cast to android.widget.LinearLayout$Layout