How do you serialize Android Intents?

Android Intents have a convenient toURI () method, which seems to indicate the API, is a way to serialize the Intent to a URI and then parse it later into intent. Unfortunately, when testing this functionality, I found that it does not serialize all additional functions, just primitive types (logical, int, long, float, String). If the intent indicates any additional or massive additions, they are lost.

Where (if any) is this restriction limited? Is there any obvious reason for this behavior (I can imagine some difficulties with Parcelables)? And most importantly, is there a recommended way to serialize and analyze intent?

My current implementation simply writes Intent components (action, categories, uri data, and additional functions) to SharedPreferences. This strategy does not support Parcelables.

+6
source share
1 answer

Android Intents has a convenient toURI () method that seems to indicate the API, is a way to serialize Intent into a URI, and then later parse it into Intent.

Not really.

Where (if in any case) is this restriction indicated?

I would not expect add-ons to be included in Uri at all. The point behind this type of Uri generation should show you how to add Uri as a link to a website, and you do not need additional features for this scenario.

toURI() not serialization.

And most importantly, is there a recommended way to serialize and analyze intent?

Not. In particular, Parcelable cannot be serialized by definition.

My current implementation simply writes Intent components (action, categories, uri data, and additional functions) to SharedPreferences.

This approach is just fancy.

Use the database. If you have been attacked by the database as a small child and, therefore, offended by the fear of databases, serialize using JSON, XML, or Serializable / ObjectOutputStream to a file. Use SharedPreferences for user preferences.

This strategy does not support Parcelables.

And should not. And this is not so. Parcelable designed to convert an object graph into a memory block for use only in a running device. This is not a long-term conservation mechanism.

+6
source

Source: https://habr.com/ru/post/889459/


All Articles