Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate to activity located in different module

I am working on application which is divided by features into modules.

App structure looks like so:

  • app (application)
    • MainActivity
    • MainApplication
  • featureOne (module)
    • FirstActivity
  • featureTwo (module)
    • SecondActivity

Feature modules cannot depend on each other, but I can edit them freely. My goal is to navigate from FirstActivity to SecondActivity.

I cannot use startActivity(Intent(com.example.featureTwo.SecondActivity)), because SecondActivity class is not visible to FirstActivity(different independent module).

Question is what is the proper way to navigate from FirstActivity to SecondActivity?

I was thinking about using:

  • Broadcast - I would send broadcast from FristActivity and register broadcast receiver, in featureTwos manifest. From broadcastReceiver I would launch SecondActivity.
  • Deep Links - Similar to the broadcastReceiver.
  • Creating function in application class and an enum within app package containint activies I want to launch. I would call this function whenever I want to launch activity like so: launchActivityFromDifferentModule(EnumWithActivities.SecondActivity).

Which method should I use, which one I shouldn't and why?

like image 290
xstmpx Avatar asked Jul 05 '19 06:07

xstmpx


1 Answers

have many approaches for lunching activity in another module

  1. Reflection

    Props: easily navigate to another class without define class in the app module.

    Cons: reflection is running at runtime.

  2. DeepLink

    Props: create a unique link for any item in another module like openFragmentA, addCreditToUserAccount, etc.

    Cons: not have a serious concern.

  3. Broadcast

    Props: declare determined activity in the app module (if have nav module setup inside).

    Cons: need more time to change and define another module.

Conclusion

Deeplink is suitable for a dynamic feature (onDemand feature) Broadcast is suitable for a main feature, permanently feature Reflection is suitable when not confident for a feature like A/B test feature

like image 151
Alireza Tizfahm Fard Avatar answered Oct 20 '22 06:10

Alireza Tizfahm Fard