Junior
List markers and interfaces in Android development.
sobes.tech AI
Answer from AI
Marker interfaces in Android are interfaces without methods used to indicate the class, providing the compiler or runtime environment with information about the object type.
Examples:
Serializable: Indicates that an object can be serialized (saved to a byte stream) for later deserialization. Used for data transfer between components, saving state.Parcelable: A more efficient Android equivalent ofSerializable. Allows objects to be "packed" into aParcelfor quick transfer. Requires implementation ofwriteToParceland creation ofCREATOR. Used for data transfer betweenActivity,Service,BroadcastReceiver.Cloneable: Indicates that an object can be cloned using theObject.clone()method.
Interfaces in Android are used to define contracts, ensure polymorphism, and callbacks.
Examples:
- Listeners (event listeners):
// Example of a click listener View.OnClickListener - Callbacks:
// Example callback for request result retrofit2.Callback - Adapters:
// Example adapter for a list androidx.recyclerview.widget.RecyclerView.Adapter - Lifecycle Observers:
// Example of a lifecycle observer androidx.lifecycle.LifecycleObserver - Runnable: Used to define code that runs in a separate thread.
java.lang.Runnable - Comparable/Comparator: For defining the sorting order of objects.
java.lang.Comparable java.util.Comparator ServiceConnection: For interacting with a bound service.android.content.ServiceConnectionBinder: Base class for implementing remote procedure calls (IPC).android.os.Binder