1

I'm sending a CharSequence of a Spannable to another Activity via intent extras, but seem not to receive the same sequence.

I'm doing that according to the following answer: https://stackoverflow.com/a/45638248/1545435

Here's the content of learnMoreText and how I'm sending it. It has 12 spans:

enter image description here

@Override
public void onItemLearnMoreClick(View view, int position) {
    Intent intent = new Intent(getContext(), LearnMoreActivity.class);
    CharSequence learnMoreText = model.getLearnMoreText(position);
    intent.putExtra(LearnMoreActivity.EXTRA_LEARN_MORE, learnMoreText);
    String learnMoreType = model.getLearnMoreType(position);
    intent.putExtra(LearnMoreActivity.EXTRA_LEARN_MORE_TYPE, learnMoreType);
    startActivity(intent);
}

Here's how I receive it in the LearnMoreActivity. Now it only contains 10 spans. The link-spans <a></a> were striped:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActivityComponent().inject(this);

    LearnMoreActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.learn_more_activity);

    CharSequence learnMoreHtmlText = getIntent().getCharSequenceExtra(EXTRA_LEARN_MORE);

    binding.contentText.setText(learnMoreHtmlText);
    binding.contentText.setLinksClickable(true);
    binding.contentText.setMovementMethod(LinkMovementMethod.getInstance());

    setupToolbar();
}

enter image description here

Can anyone point to the reason and how to fix?

Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
Ambran
  • 2,367
  • 4
  • 31
  • 46
  • OK, as no one had a clue about this after 24 hours, I ended up passing the required parameters to generate the `learnMoreHtmlText` Spanned (which is the CharSequence I tried to pass) again directly in the `LearnMoreActivity`. My problem is solved, though less elegantly then it could have been had the CharSequence been passed correctly via the Intent. – Ambran Apr 26 '18 at 07:59
  • I'll let this question live on in hope someone posts a solution to it some day, which can help others, as this *is* a strange behaviour which makes me think this is a bug. – Ambran Apr 26 '18 at 08:00
  • I'm not sure what are you using for link-spans, looking into the docs, some spans are [`ParcelableSpan`](https://developer.android.com/reference/android/text/ParcelableSpan) and some aren't. For example [`URLSpan`](https://developer.android.com/reference/android/text/style/URLSpan) is parcelable, whereas [`ClickableSpan`](https://developer.android.com/reference/android/text/style/ClickableSpan) is not. May be the parcelable types can live through intent, because they can be re-constructed later via parcel interface. – Adil Soomro Mar 30 '20 at 17:23

0 Answers0