Briefly said that my question is: in the MVP architecture, is it nice to use the Service as a Leader to manage a model implemented as a Service?
Alternative question: Does the Service use a good idea to manage another Service?
Context:
I am writing an application that communicates with a Bluetooth sensor. The application has a Service (aka BluetoothService
), which provides a connection and controls communication with the sensor. The application has several fragments, but only a few of them are associated with the operations that the Bluetooth sensor. The user should be able to start the operation, switch to different fragments and later tracks the results of the operation (operations) performed by the sensor.
My goal:
I want to write a component (aka BluetoothController
) that makes links between the sensor (presented in my BluetoothService
application) and the rest of the application. BluetoothController
contains objects that describe what kind of work the sensor should perform (only one operation, sequential operations, type of operation, ...), so the purpose of the BluetoothController
is to allow the operations to be independent of the Bluetooth sensor, and then they can test the application with the bluetooth mock class. I see BluetoothService
as a model and BluetoothController
as a presenter, am I wrong?
Why service:
- Since it does not die if the user moves between fragments
- Since it is accessible through the entire application via
bindService
- Because
bindService
is the only entry point, I think I can control this one operation is performed simultaneously - Because I see the Service as an active component, so it can continue to receive data, even if nothing is connected with it.
This service will be started and bound (for example, a music player):
- to work, even if no components are attached to it,
- to facilitate communication.
All services will be in the application process to provide communication without a call method invocation.
Any suggestion would be highly appreciated, thanks in advance
Why not something else:
- RetainedFragment (for me) is just a container
- A host is only a gateway between views and models; they must die if they are not attached to the view.
Conclusion
Am I really wrong? Do you see difficulties in this architecture? Are there any other Android components that are better suited for my purpose?
Any suggestions would be highly appreciated, thank you for your success.
source share