Make a Component of Android Project for use it inside another android project

102 views Asked by At

I will try to explain what I realize and I hope to be clear.

I have an existing Android project (Project A) and a third company developed android project (Project B) (with different package) that should be integrated within my project. So from a Button of my project (A) I have to open a activity of Project B passing a parameter.

I don't know how I can do this.

A solution that I tried is as follows. By the project (B) in the Manifest I removed the activity with "android.intent.category.LAUNCHER" and I set to respond to a certain intent. Then I created a project reference B within my project A. Button and the launch of the project in the intent to set me and everything works. (see here: launch activities from different package) The problem is that in the phone will be installed both projects. Only the Project A is visible in the menu, but in the list of applications both exist. This thing should be avoided.

A second attempt I made was to export the project (B) in Jar and then include it as internal or external Jar in my project. But in this case, I'm not able to create an intent to open the activity of the project B These some of my attempts:

Intent intent = new Intent("applicationB.intent.action.Launch");
startActivity(intent);

//OR

Intent intent = new Intent(MainActivity.this, ActivityInizio.class);
startActivity(intent);
//(ActivityInizio in the activity of project B That is imported in my project from Jar)

//OR

Intent intent2 = new Intent();
intent2.setComponent(new ComponentName("aa.bbb.ccc","aa.bbb.ccc.activity.ActivityInizio"));
startActivity(intent2);

Whatever I try, I always get a ClassNotFoundException or something similar.

How can I achieve my goal to include in my project the second project and then be able to use it properly? Can anyone help me?

Thank you.

1

There are 1 answers

1
Hana Bzh On BEST ANSWER

You can use that project as a library for your project.

Just create a library project (Project B). Then add Project B as a library to Project A.

Some useful resources:

Getting started with android library project

How to add a Library Project to a android project?

how to start activity defined in library project

Starting Activity from Android-Library-Project