1

Is possible to save a CharSequence variable into Firebase?

Checked out: Supported Data Types, but charsequence is not there...

I'm getting serializable problems related to this, tried: pro-guard rules, public attributes, implements serializable, etc; but I'm not able to save charsequence into Firebase.

Is anyone able to help me out with this?

PS: it needs to be a charsequence, not a string!

allenski
  • 1,652
  • 4
  • 23
  • 39

2 Answers2

1

You can save a CharSequence to Firestore by converting it to a String with its toString() method. If you read the string back from Firestore, it will be a String object, which implements CharSequence as well. You will not be able to use automatic serialization with a CharSequence interface. The SDK won't know which implementation of CharSequence to create for you when you read the data back out.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Ok, we can say that a String is a type of Charsequence, but I'm not asking this way, because i'm trying to use SpannableString and i need to store in firebase a text with its mark ups, do u understand?Because i need to retrieve data with it's mark ups... –  Mar 12 '18 at 19:26
  • OMG,man...what can i do? (o_O)'', i'm getting serializable error whe i try to store a Charsequence =( –  Mar 12 '18 at 19:32
  • Yes, read my answer again. You can't do that. Convert it to a String first. – Doug Stevenson Mar 12 '18 at 19:40
0

To store markup text(or CharSequence) in database(may be Firestore) you may use Html.toHtml(Spanned text) function from android.text.Html class which return styled html string. To retrieve markup text back use Html.fromHtml(String html). You may find android reference here.