android10 / android10/Android-CleanArchitecture
Layer for Managers and Services that require Android Context
- Dominant language
- Java
- Stars
- 15.5k
- Forks
- 3.3k
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I am trying to migrate to `Clean Architecture`.
I have application which is made in standard way, I tried to decouple, but still a lot of stuff happens in `Activities` and `Fragments`.
Example is quite simple, mostly applications are much more complex so it is much harder to decouple all highly coupled components inside application.
I have just faced with one problem is Managers and Services that requires `ApplicationContext` or `ActivityContext`.
For example I have `LocationManager` which is responsible for getting location, but it requires context, at least to get `Service` and to listen to lifecycle of `Activity`.
I think this manager could go to `Data` layer, but this is undesirable dependency.
I really don't want to put this login into presentation layer. I firmly believe that `Presentation` layer should be just UI and ONLY UI nothing more, unfortunately `Android SDK` is build in a way that we have `God Object` - `Activity` but I still wanna to get rid of anything except use cases in `Presentation` layer.
I see some ways how this can be solved :
1. Add new layer or sublayer which will be responsible for handling all Context related stuff and call it for example `Service` or `Lifecycle` layer and make it tight to context lifecycle, also in order to keep things abstract interface with common lifecycle methods can be created (`onCreate`, `onDestroy` ...)
and injected via dependency injection tool like our beloved `Dagger 2`
2. Without separate layer there is only one way is to add `Android` dependency to some layer. Presentation layer is already coupled to `Android Context`, but again UI should be UI nothing more, consume, update, and request data through `Use cases` from domain layer.
Furthermore one important thing to note that `LocationManager` is great example of publisher/subscriber pattern so it can be easily adopted to `RxJava`.
All things considered, I would be grateful for any thoughts, advice on this problem.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.