2

I am using Conductor (https://github.com/bluelinelabs/Conductor) for Android to replace Fragments. I was implementing image picking in my app and realized that onActivityResult is called before Controller's onAttach, in case of Fragments, equivalent would be onResume. It would be fine, but my problem is that I use coroutines and the coroutine context is created when my presenter is attached (which is a presenter.attach() call from onAttach of Controller (onResume of Fragment)). From onAcitivtyResult I call a function that saves the selected image path to a database. This call requires context to be already be created. I was wondering what people do in this situation. If I am not mistaking, in Fragments, onActivityResult is also called before onResume, so this question is probably not specific to Conductor.

Sermilion
  • 1,920
  • 3
  • 35
  • 54
  • Fragments create their [`lifecycleScope`](https://developer.android.com/topic/libraries/architecture/coroutines#lifecyclescope) either at construction or as part of their view creation, both of which happen well before `onActivityResult()`. `onResume()` is never the right place to be doing context creation (it is either way too late or called way too often). – ianhanniballake Oct 16 '20 at 00:24

0 Answers0