Search code examples
androidkotlindependency-injectiongit-submoduleskoin

Kotlin: How to send/receive data with submodules


I have a project with submodules which are injected (through Koin DI) but I have no idea how to send and receive data between them. Here is the project structure and requirements:

mainModule
|__ mainActivity starts subActivity1 through Koin dependency injection > then requires responses from subActivity3, then must respond back.

subModule1
|__ subActivity1 > calls subActivity2
|__ subActivity2 > calls subActivity3
|__ subActivity3 > how to return values to mainActivity and continue receiving responses from MainActivity after that?

Any direction is appreciated.


Solution

  • Please try this way

    (1) startActivityForResult(subactivity1) from mainactivity (2) in subactivity1 again call startActivityForResult(subActivity3) (3) now from subActivity3 code like setResult(RESULT_OK, intent) (4) now first get result inside onActivityResult of subactivity1 and from there you rerurn the result to mainActivity with this setResult(RESULT_OK, intent)

    if above solution not fit in existing, then try with static variable true and false when complete task from subactivity3 to mainactivity class in onStart() method and false that varibale here

    or you can use Reactivex programming to publish and listen with RxBus or broadcast receiver at last.

    hope it may help you