MAD
MAD
@Override
public IBinder onBind(Intent intent) {
return null; // For unbound services
}
}
Communication Between Service and Activity:
Using Broadcasts: Services can send broadcasts that activities can listen to.
Using Binder: A bound service allows direct communication with the
activity through a Binder object.
java
Copy code
public class MyService extends Service {
private final IBinder binder = new MyBinder();
@Override
public IBinder onBind(Intent intent) {
return binder;
}
}
Threading:
Android services can run on separate threads to prevent blocking the main UI
thread. This is crucial for long-running operations like network requests or file IO.
Using AsyncTask (deprecated, but still used in legacy apps).
Using Handler for communication between threads.
Using ExecutorService for managing multiple background threads.