1

I'm new to android and am trying to make an application that when the user presses a particular button in App A, he is sent to App B. The user can then come back to App A by pressing another button in App B. No content is transferred from one app to another.

I want to accomplish this by making custom intents for both the applications. How should I start with this? Also what exactly is Broadcastreceiver and do I need to use it for the above mentioned problem?

Thanks!

Ankush
  • 6,767
  • 8
  • 30
  • 42

2 Answers2

4

Switching between another Application can be by two ways that is

1.) If you know the MainActivity of the Application to Call, you use

    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setComponent(new ComponentName(
                                "package_name","package_name.MainActivity"));
    startActivity(intent);

2.) If you don't know the MainActivity to Call you just use PackageName, you use

    Intent LaunchIntent = getPackageManager()
                                  .getLaunchIntentForPackage("package_name");
    startActivity(LaunchIntent);

I don't think you need a BroadCastReceiver here as it is what you use when you want to catch some event/action for eg- Low Battery. For further details check my answer here

Community
  • 1
  • 1
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
1

See Code to launch external app explicitly (especially this answer). You'll have to create a custom intent for each of the applications, and then call that intent explicitly.

In App A Manifest:

<intent-filter>
    <action android:name="com.mycompany.APP_A" />
</intent-filter>

In App B Manifest:

<intent-filter>
    <action android:name="com.mycompany.APP_B" />
</intent-filter>

In App A Button Press:

Intent intent = new Intent();
intent.setAction("com.mycompany.APP_B");
startActivity(intent);

In App B Button Press:

Intent intent = new Intent();
intent.setAction("com.mycompany.APP_A");
startActivity(intent);
Community
  • 1
  • 1
David
  • 1,698
  • 16
  • 27