Sobes.tech
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 of Serializable. Allows objects to be "packed" into a Parcel for quick transfer. Requires implementation of writeToParcel and creation of CREATOR. Used for data transfer between Activity, Service, BroadcastReceiver.
  • Cloneable: Indicates that an object can be cloned using the Object.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.ServiceConnection
    
  • Binder: Base class for implementing remote procedure calls (IPC).
    android.os.Binder
    
List markers and interfaces in Android development… - sobes.tech