• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

How to link to another activity in other module same project

RK88

Lurker
Hi,

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?

Thanks in advance.

RK88
 
There are two possible ways, I know:
1. Two independent modules in one project
Another module in your app is independent application with own package and Manifest. Do not confuse it with another android library.
We are talking about Phone/Tablet Module.
You can call it like another application via PackageManager
https://stackoverflow.com/questions...plication-from-another-application-on-android
Please find demo project with two absolutely independent modules placed in one project https://github.com/v777779/aad_20180426
Download project, open in Android Studio 3.1, Start one module "app". Start another module aad_20180426a.
Now both modules installed into device or emulator. Then click on FAB on any of module. You will switch between them back and force.

2. One module app and android library module
Please find demo project app with android library module https://github.com/v777779/aad_20180426b
The main difference, that this is one application. App module is master, library module is slave.
MainActivity can call any activity from library module.
But you can't call MainActivity from library module. You can back to MainActivity via onBackPressed().
 
Last edited:
Hi v777779,

Thanks for your reply. Appreciate.

Yes. I am talking about 2 Phone/Tablet Modules currently.
However, what I wanted to achieve is actually what you had mentioned in the last para - to appear as one application in the phone.

Conclusion, I guess I have to convert module B to a Android library instead.

Thanks a lot.
 
Hi,

After making the changes(ie convert module B to library), I tried to deploy the app into the android phone. I realised after the apk had been installed, 2 icons appeared on the phone.

The 1st icon will load the module A activity and the 2nd icon will load the module B activity. Is this the expected behaviour? Because I was thinking it should only show one app icon on the phone. Module B activity should only be access via module A.

Question
How to achieve only one app icon?

Thanks.
 
I think you should make test project with two modules, one main module, second library.
Then compare manifests of the test project with your target project manifests.
And remove all unnecessary properties from the library module manifests of your target project.
I think second icon provided by manifest's application line "android:icon="@Mipmap/ic_launcher"
 
Back
Top Bottom