无效的有效负载类型Android

时间:2014-02-16 04:30:05

标签: android android-actionbar-compat

在新的更新之后,我发现了操作栏和LG设备中spannable / formatted字符串的兼容性问题。

以前是我的代码:

SpannableString s = new SpannableString("About");
s.setSpan(new TypefaceSpan(this, "Sansation-Regular.ttf"), 0, s.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getSupportActionBar().setTitle(s);

我相信setTitle崩溃时会出现这个错误:

java.lang.IllegalArgumentException: Invalid payload item type at android.util.EventLog.writeEvent(Native Method)

这会解决任何潜在的问题吗?我是Android新手所以不知道。因为问题似乎只发生在使用actionbarcompat运行4.1.2的LG设备上 - 但是因为我计划在未来添加对较低API级别的支持,所以我现在不想摆脱actionbarcompat。

SpannableString s = new SpannableString("About");
s.setSpan(new TypefaceSpan(this, "Sansation-Regular.ttf"), 0, s.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
try{
    getSupportActionBar().setTitle(s);
}catch(IllegalArgumentException e) {
    getSupportActionBar().setTitle("About");
}

感谢!

PS:有问题的设备是LG正在运行4.1.2

1 个答案:

答案 0 :(得分:5)

显然这是Android本身的一个错误。它通过以下提交修复:

commit 332944f8a0a001c1754ce3298edbb4246e53c8fb
Author: zobject <zbjection@gmail.com>
Date: Mon Dec 10 22:52:59 2012 +0900

 Fix EventLog string class problem in onOptionMenuSelected

 EventLog function can handle string,integer class and long class. (in android_util_EventLog.cpp)
 If menu title string are used bold tag(like <b>test</b>), it'll be android.text.SpannedString.
 In onOptionMenuSelected, it is using item.getTitleCondensed() function for writing event log.
 therefore any android activity using tag menu string(like <b></b>) can be crashed by IllegalArgumentException.

 I found this crash on GMS Application.
 change locale chinese -> launch Google+ -> hangout -> menu key -> Invite(expressed chinese) click -> Google+ crash

 Change-Id: I0437be81699925e29bf4510eb615ef2424432763