Reputation: 835
I wondered if it makes sense to make a class that inherits from the Intent class and that overloads the putExtra method, allowing to pass custom objects, instead of using Parcelable. Is it something sensible? Is it much slower than passing parcels?
I would like the process to be extremely fast, keeping the object in memory, and from what I understand, parcels use serialization instead.
Upvotes: 0
Views: 311
Reputation: 8575
It's an interesting question. Intent is a universal data wrapper that, among it's other functions, allows you to transfer data between processes, that's why you need your data in parcelable form. In fact the intent itself is parcelable, and to implement a proper subclass you'll need to parcel all your added fields and you'll basically end with the same intent class, just with a few exposed fields. Here is a subclass of Intent for reference: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/content/pm/LabeledIntent.java
So I would not recommend you to follow this approach. If you want an alternative way of sending data between different components I would recommend you to use concept of EventBus and create something like https://lorentzos.com/rxjava-as-event-bus-the-right-way-10a36bdd49ba
Upvotes: 1