3

I want to combine 2 android projects together in such a way that when an button is pressed from one activity (of 1st project ) it should start my activity from (2nd project) both the projects are fully functional applications.. it is just that they were developed in parts i tried a lot of searches entire but ended up being frustated can someone provide me with a simple way to do so

the activity i am trying to call is

MainActivity.java from 2nd project when a button is pressed from activity in first project

i want to combine the projects together..so that i can export it as a single apk...

Rahul Mehrotra
  • 639
  • 5
  • 15
  • 31

2 Answers2

6

The answer depends on what you intend to do with the projects.

If you wish to merge the project into a single app , at least one of them should be set as an android library , and another project should use it . This way , the merged projects would be able to recognize each other .

If you wish to have 2 apps and not a single app , each activity that you wish to access from another activity should have a special definition in the manifest (using intent filter) of how to open it , as it's not the default behavior .

android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • well you choose a project , choose its properties , go to the "android" category , and choose that it is a libary . Then , you go to the other project that should use it , and go to the same place but you choose to add a library . do note that all resources are also merged , so if you have a drawable file in the library project called "image2.png" and the same file in the project that uses this library , only one will be used (the one from the project that uses the library) . also , you should change the manifest so that it could handle the activities from the library. – android developer Feb 20 '13 at 12:06
  • i got the error fixed...still confused..how to call the activity from library – Rahul Mehrotra Feb 20 '13 at 12:17
  • after you merge the projects , you will be able to call the activity as if it was a part of the project that uses the library . nothing special . – android developer Feb 20 '13 at 12:18
  • i tried, it worked...I get the MainActivity.java Screen .....however if i click futhur(there is a button on the activity which invokes other activity from same project) it force closes and get an error msg 01-17 21:54:06.171: E/dalvikvm(10925): Could not find class 'com.rahul.example.PlacesMapActivity', referenced from method com.rahul.example.MainActivity$1.onClick – Rahul Mehrotra Feb 20 '13 at 12:31
3

If all you need is to show a new MainActivity instance you need to declare an intent-filter in your "2nd project" manifest:

 <activity android:name=".MainActivity">
   <intent-filter>
     <action android:name="your.package.here.MainActivity" />
     <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
 </activity>

Then create an intent with the same action string in your first project:

Intent intent = new Intent("your.package.here.MainActivity");
startActivity(intent);
a.bertucci
  • 12,142
  • 2
  • 31
  • 32
  • i was searching through some post...and it said to mark it as a library..and use it..still didnt get how to do that http://stackoverflow.com/questions/7950677/combine-2-android-apps – Rahul Mehrotra Feb 20 '13 at 11:59