Reputation: 127
I have a multi module architecture android project, where there are modules like module A, module B, module C and shared common module. Each modules code is private. Other modules cant access directly, shared module is the only module which is accessible by every other module.
Scenario:
In Module A, I need to call a sdk method, Which takes around 5 min, which gives a continuous progress values in integer. That progress is shown in dialog box. Now user hides the dialog box and moves to other part of the app say ex: Module B's fragments. I need to make sure that sdk method is still in progress and able to get that progress in Module B as well.
Solutions tried:
Workmanager: If i try to add a sdk method code in doWork method and start the workmanager. Able to observe the progress through live data in other component. However i am facing a limitation in starting a workmanager since to start a sdk method inside doWork method i need to pass a object to sdk method. That object is more than 10Kb so cant pass it through workparameters and also cant globally save that object due to security issues.
Coroutines: If i just tried using scopes, there is no common viewmodel between multiple modules. so if i start a sdk method from Module A, If user moves to different module's fragment viewmodel destroys.
Foreground service: I cant use foreground service. Due to security issues i cant show the device notification.
So is there any better approach to accomplish the above task?
i have gone through android background doc of google Android Background doc Google suggest to use workmanager for long running persistance case. But mine is a requirement of long running impersistance case. however one more requirement of mine is during sdk call. If app closes, I dont want to resume that task as well once app restarts.
Upvotes: 0
Views: 47