0

Background
I have two android modules - A & B within a single project.
Each module has their own layouts

What I want to achieve
When I click a button in module A, it will start the main activity in module B and display the module B layout.

What I had tried - Not successful

  1. include module B in module A
  2. create Intent to start module B activity

Question
How can I achieve this? What are the possible ways?

ps: in the end I want one apk file .

Thank you very much for your time and assistance on this matter.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
  • IMO, You can convert module B into a library and add it to A. Take a look at this link https://www.quora.com/How-can-I-merge-combine-multiple-projects-into-one-in-Android-Studio – Okeme Christian Mar 21 '19 at 12:16

1 Answers1

0

You need to use a connector to your other module by using a Navigator class. The Navigator should be the only way to access the activity inside the module. The Navigator is a singleton class.

You can create a Navigator class inside your library module (in your case, your module B) with something like this:

public class Navigator {
    private Navigator(){}

    public static Navigator getInstance() {
        return NavigatorHolder.INSTANCE;
    }

    private static class NavigatorHolder {
      private static final Navigator INSTANCE = new Navigator();
    }

    public void navigateToMainActivityB(Context context) {
      Intent intent = new Intent(context, MainActivity.class);
      context.startActivity(intent);
    }
}

Then you can launch the MainActivity of B module with:

Navigator.getInstance().navigateToMainActivityB(ModuleA_Activity.this);
ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96