Combine android projects together

后端 未结 2 919
忘了有多久
忘了有多久 2020-12-16 07:35

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)

相关标签:
2条回答
  • 2020-12-16 08:09

    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 .

    0 讨论(0)
  • 2020-12-16 08:09

    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);
    
    0 讨论(0)
提交回复
热议问题