Ask Your Question
2

How can I use implicit intent to switch between two of my own Android apps?

asked 2023-05-21 07:21:22 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-05-21 07:29:02 +0000

plato gravatar image

To switch between two of your own Android apps using implicit intent, follow these steps:

  1. Add an intent filter to the activity in the receiving app that you want to launch. In the AndroidManifest.xml file of the receiving app, add the following code snippet within the <activity> element:
<intent-filter>
    <action android:name="com.example.myapp.ACTION_SWITCH" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
  1. In the sending app, create an Intent object and set its action and package name to launch the receiving activity. For example:
val intent = Intent("com.example.myapp.ACTION_SWITCH")
intent.setPackage("com.example.otherapp")
startActivity(intent)
  1. Ensure that the receiving app is installed on the device, and that the package name in the Intent object matches the receiving app's package name.

  2. Run both apps and invoke the Intent from the sending app to launch the receiving activity.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-21 07:21:22 +0000

Seen: 17 times

Last updated: May 21 '23