android / android/architecture-samples

I need advice. branch/todo-mvp-clean. LongRunningUseCase

Open
#154 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Kotlin
Stars
45.8k
Forks
11.9k
PR merge metrics
No merged PRs in 30d

Description

Suppose there is such [UseCase](https://github.com/westman2000/MVPCAndroid/blob/mvpc-loaders/app/src/main/java/corp/wmsoft/android/examples/mvpc/longrunning/iteractor/LongRunningUseCase.java)

And [Presenter](https://github.com/westman2000/MVPCAndroid/blob/mvpc-loaders/app/src/main/java/corp/wmsoft/android/examples/mvpc/longrunning/LongRunningPresenter.java) who using it.

When user start UseCase, i show loading, but because this is long running operation, user can close this screen(press back button, close activity), or even close application(press home button).
In this case, will be called detachView() and onDestroyed() ([presenter will be destroyed here](https://github.com/westman2000/MVPCAndroid/blob/mvpc-loaders/mvpcandroid/src/main/java/corp/wmsoft/android/lib/mvpc/presenter/loader/MVPCPresenterLoader.java))

But since the operation is continued in the background, presenter will receive
`onSuccess(LongRunningUseCase.ResponseValue response)`
but because view already detached, there will be Error.

And my questions are:
1. How to avoid this error? I understand i can just check if view is attached `isViewAttached()`. but maybe there is a more elegant solution? For example how I can unsubscribe from UseCase if presenter destroyed, and then callback will not be called?
2. I do not understand how and why there is a function call `onSuccess` in the presenter, if presenter was already destroyed in `MVPCPresenterLoader.onReset()`
3. Somebody thought to create an intermediate buffer(let's called ViewState) between the Presenter and View to save commands for the View. In case you Presenter was disconnected from the View, and background thread finish loading, we need to hide the ProgressBar and display data. But this commands must be send to View only after attachView... In generally i speak about somesing like [this](https://github.com/Arello-Mobile/Moxy/wiki)

Contributor guide

Open the contributing guide

Research direction

Start by reading LongRunningUseCase.java, LongRunningPresenter.java, and MVPCPresenterLoader.java, focusing on detachView(), onDestroyed(), onReset(), and onSuccess(). Trace the lifecycle and callback path, then review the linked Moxy ViewState discussion. Done would require an agreed, documented lifecycle behavior for completion after the view or presenter is gone.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, java
Domain
mobile-dev
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.