- Foreground services run in the foreground and can avoid being recycled by the Android system when low on resources. They can be interacted with by the user through notifications.
- Started services run indefinitely in the background until stopped or destroyed by the system. They are launched by other app components like activities or broadcast receivers.
- Bound services can return results and interact with the component that started them, unlike started services. They allow sending data to the launching component.
- IPC allows two processes or apps to communicate by passing data. On Android, processes cannot access each other's memory directly, so IPC provides channels for communication using messengers or AIDL.
2. Foreground Service
• it always run in foreground.
• this can avoid service object being recycled by android
system when android os do not have enough resources.
• Android foreground service can be interacted by user
through notification.
3. Started Service
• Started services are those that are launched by other
application components like an Activity or a Broadcast
Receiver.
• They can run indefinitely in the background until stopped
or destroyed by the system to free up resources.
4. Bound Service
• Started services cannot return results/values or interact
with its starting component.
• Bound services on the other hand can send data to the
launching component (client).
5. IPC
• IPC means Inter Process communication where two
applications or processes will communicate with each
other by passing some data between them.
• On Android, one process cannot normally access
the memory of another process.
• In both cases, the system must provide a "channel" that
allows two processes to communicate.
• IPC with Messenger and Handler
• IPC with AIDL (Android Interface Definition
Language)
6. Messenger
• messages to be passed across process boundaries
between client (client component) and server (service).
7. AIDL
• AIDL allows you to define the programming interface that
both the client and service agree upon in order to
communicate with each other using interprocess
communication (IPC).
8. Compared to AIDL
• When you need to perform IPC, using a Messenger for
your interface is simpler than using AIDL,
because Messengerqueues all calls to the service.
• A pure AIDL interface sends simultaneous requests to
the service, which must then handle multi-threading.
• For most applications, the service doesn't need to
perform multi-threading, so using a Messengerallows the
service to handle one call at a time.
• If it's important that your service be multi-threaded,
use AIDL to define your interface.
9. When Use AIDL
• Using AIDL is necessary only if you allow clients from
different applications to access your service for IPC and
want to handle multithreading in your service.
• If you do not need to perform concurrent IPC across
different applications, you should create your interface
by implementing a Binder or,
• if you want to perform IPC, but do not need to handle
multithreading, implement your interface using a
Messenger.
11. Inter Process
Communication (IPC)
• AIDL service provides IPC.
• When any task completed service will send response to
activities that actually bound that service
12. Remote Procedural Call
RPC
• AIDL service also provides RPC.
• When Activity request for data, Service will response
back instantly.
14. IPeer.aidl
• When PEER_CHANGED event found new MeshID then
we convert that to MeshPeer.
• MeshProvider will sent this MeshPeer as a callback to
HotPotato Service via IPeer.aidl
• Activity that wants to be notified when new Peer
discovered , will register this callback via
getPeerInfo(IPeer peer)
• When Service receive the callback it will send
response to bounded activity.
15. Idata.aidl
• When DATA_RECEIVED event found new Data then we
convert that to MeshData.
• MeshProvider will sent this MeshData as a callback to
HotPotato Service via IData.aidl
• Activity that wants to be notified when new Data received
, will register this callback via getData(IData data)
• When Service receive the callback it will send
response to bounded activity.
16. RPC methods
• From Activity if we want peers List then activity will make
a RPC call to AIDL service via getPeersLists().
• According to request Service will response back with
peer list.
• From activity if we want to send message then again
activity will make a RPC call with
sendMessage(MeshData data)
• If we want self peer from activity then make a RPC call
with getSelfPeer();