How to call an activity in another project?

前端 未结 5 674
无人及你
无人及你 2021-01-18 22:22

Hi I am new to android and I have created 2 projects.

Now I want to call an activity in the second project from the first project upon a button click.

The 1

相关标签:
5条回答
  • 2021-01-18 22:50
    1. in the map project's AndroidManifest file add your custom intent filter

       <!-- add custom action -->
       <activity android:name="MapActivity"
                  android:label="@string/mapLabel"
              >
                  <intent-filter>
                      <action android:name="com.example.map.show" />
                  </intent-filter>
              </activity>
      
    2. from the login button call this activity like this:

    Intent intent = new Intent("com.example.map.show"); startActivity(intent);

    0 讨论(0)
  • 2021-01-18 22:54

    You should be using one project for each application. If you want to split up your login from the rest of your application you could use different packages. Unless I am misunderstanding what you mean by "project"?

    0 讨论(0)
  • 2021-01-18 22:57

    According to Android you can handle this by making the project Library and then Define it in the manifest file and call it in what ever manner you want

    for an explanation i did this as per my requirement the activity you want to call on Button click Define it in the Manifest with its full package name and then when you call it on button click the activity of the new project will trigger the sample to do this is following in the manifest file of your 1st project define some thing like this

    <activity 
            android:name="packagefull.activityname"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
    
        </activity>
    

    in the package name define the full path of the the activity you want to call and after the package name give the name of the activity hope this will work for you as this worked perfect for me

    0 讨论(0)
  • 2021-01-18 22:57

    Use this:

    Intent i = new Intent(Intent.ACTION_MAIN);
    i.setComponent(new ComponentName("app package name", "app launch activity's classname"));
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    startActivity(i);
    
    0 讨论(0)
  • 2021-01-18 22:58

    This is really not a good way for developing any application. But still if you want to achieve this , you will have to declare an Intent Filter for the target activity in that application's Manifest file and use it as implicit intent from your login activity.

    Inside project A's Manifest:

    <activity android:name="com.example.android.TargetActivity">
                 <intent-filter>
                    <action android:name="com.someone.wants.to.call.me"></action>
                </intent-filter>
    </activity>
    

    Inside project B's Activity:

    Intent intent = new Intent("com.someone.wants.to.call.me");
             startActivity(intent);
    
    0 讨论(0)
提交回复
热议问题