8

After a new update, I've discovered an issue with the compatibility of spannable/formatted strings in action bars and LG devices.

Here's my code before:

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

I believe on setTitle is when it crashes and gives this error:

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

Would this fix any potential issues? I'm new to Android so wouldn't know. Because the issue seems to only happen with LG devices running 4.1.2 using actionbarcompat - but because I plan to add in support for lower API levels in the future, I don't really want to get rid of actionbarcompat for now.

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");
}

Thanks.!

PS: Device in question is LG's running 4.1.2

Jerryl15
  • 548
  • 3
  • 10
  • what is the android version?? – Raghunandan Feb 16 '14 at 04:34
  • 2
    I was reading another thread and apparently only effects LG devices running 4.1.2 that is running actionBarcoMPAT – Jerryl15 Feb 16 '14 at 04:35
  • what is the min sdk in manifest? if it above 11 then use `getActionBar` – Raghunandan Feb 16 '14 at 04:36
  • Oh i see, so this will also work? in stopping the error. So for safe measure is it possible to do what I did in the catch part? – Jerryl15 Feb 16 '14 at 04:39
  • what is your min sdk in manifest? – Raghunandan Feb 16 '14 at 04:45
  • 1
    min sdk is 14, but I can't reproduce the error in the emulator running any sdk 14+, seems to only happen on LG devices running 4.1.2 – Jerryl15 Feb 16 '14 at 04:48
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/47584/discussion-between-raghunandan-and-jerryl15) – Raghunandan Feb 16 '14 at 04:49
  • 1
    I'm having the same issue but I'm not using actionbarCompat, just regular ActionBar, and getting "Invalid payload type" on LG devices on 4.1.2 Did you managed to fix this? I'm also setting ActionBar's title with a SpannableString – Rodrigo Apr 01 '14 at 15:42

1 Answers1

5

Apparently this is a bug in Android itself. It is fixed with the following commit:

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
Randy Sugianto 'Yuku'
  • 71,383
  • 57
  • 178
  • 228