Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle result if activity is destroyed #11

Closed
AlexisQapa opened this issue Mar 21, 2018 · 10 comments
Closed

Handle result if activity is destroyed #11

AlexisQapa opened this issue Mar 21, 2018 · 10 comments

Comments

@AlexisQapa
Copy link

Hi,

Would this lib allow a result to be passed across multiple activities like :
A need result D produce result But B is destroyed by android
A -> B (destroyed) -> C -> D

@aartikov
Copy link
Owner

No, it doesn't. Alligator uses startActivityForResult and setResult to pass a result. So a result can be returned to a previous activity only.

@AlexisQapa
Copy link
Author

AlexisQapa commented Mar 21, 2018

So there is no way build build something like goBackToWithResult ?

the flag Intent.FLAG_ACTIVITY_FORWARD_RESULT allow to forward a result to the parent of the parent if the parent if finished.

@aartikov
Copy link
Owner

aartikov commented Mar 21, 2018

I suppose it is possible. I will think this through.

@AlexisQapa
Copy link
Author

I found that this flag also have its flaws as depending of activities count in the flow it's hard to manage something that always works. I have another lead though we can always start activities for results, as I think this is what you already do, and always finish if result is ok but not handled.
handleResult() else if (resultCode == RESULT_OK) { // If there is a result but we can't handle it, we should be in a flow so stop and pass the result to child setResult(resultCode, data) finish() }

what do you think about this ?

@aartikov
Copy link
Owner

Thank you for the good ideas.
Passing result by chain will likely work, but it will require significant changes in a library. I don't start every activity for result, just activities that are registered appropriately. I also use request codes to identify how to retrieve a result from an intent.

So I decided to pass a result directly from the last activity to the first one in the chain through onNewIntent callback. It works fine. I push my current progress to this branch https://github.com/aartikov/Alligator/tree/feature/go-back-to-with-result
I will recheck if everything is ok and make a release soon.

@AlexisQapa
Copy link
Author

Nice job on the branch ! One thing thought, I think on newIntent is not called if the activity was destroyed and the intent would be passed in onCreate. So both methods should call the code that handle the resutlt according to http://www.helloandroid.com/tutorials/communicating-between-running-activities. It's an old link but I didn't found any thing clearer than this.

@aartikov
Copy link
Owner

No, result handling should not be called in onCreate, because getIntent() will return an intent that started an activity, but not the one that was used to go back to it.
I assume that nobody will goBackTo or goBackToWithResult to the screen that is not present in the stack. It would be ideally to get ScreenNotFoundException in that case (as it happens with fragment screens), but I have not found a way to implement it reliably for activities.

@Alex293
Copy link

Alex293 commented Mar 27, 2018

While I understand you point I still think that an activity can be in the back stack and been killed then recreated

@aartikov
Copy link
Owner

I have checked that onNewIntent is called even if an activity has been recreated.

@aartikov
Copy link
Owner

Version 2.2.0 with this feature is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants