Introduction: Why Call an Activity from Another App?
\n\nImagine you are creating a note-taking app and want to give the user the ability to take a photo directly from your interface. Or, suppose your messenger needs to open contacts from the address book. In both cases, you need to launch an Activity from another app in Android.
\n\nThis task is one of the most popular questions on Stack Overflow (thousands of views and hundreds of votes). And for good reason: if done incorrectly, the app may crash with an ActivityNotFoundException or, even worse, create a security risk. In this tutorial, we will cover all the nuances in Kotlin so you can confidently integrate external screens into your projects.
By the way, you are on the PythonLib website, where we often talk about Python, but today is a special case. Android development in Kotlin is a powerful skill that pairs well with a Python backend. Let's go!
\n\nWhat is an Intent and Why is it the Key to the Solution?
\n\nIn Android, an Intent is a message that tells the system: "Hey, I need to do something with this action." For launching an Activity from another app, two approaches are used:
\n\n- \n
- Explicit Intent — you know exactly which component you want to launch (e.g.,
com.example.target.MainActivity). It only works if you have access to that app's code. \n - Implicit Intent — you describe what you want to do (e.g., "open a map at these coordinates"), and the system itself finds a suitable app. This is a more flexible and secure way to call an external Activity. \n
We will focus on implicit Intents, as they are most commonly used for Android interprocess communication.
\n\nBasic Example: Opening a Map by Coordinates
\n\nLet's start with a simple example that demonstrates how to launch an Activity from another app to display a map.
\n\n// Kotlin\nval gmmIntentUri = Uri.parse("geo:55.7558,37.6173?z=15")\nval mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)\nmapIntent.setPackage("com.google.android.apps.maps")\n\n// Check if there is an app that can handle the Intent\nif (mapIntent.resolveActivity(packageManager) != null) {\n startActivity(mapIntent)\n} else {\n // Show an error message to the user\n Toast.makeText(this, "Google Maps is not installed", Toast.LENGTH_SHORT).show()\n}\n\nWhat's happening here? We create an Intent with the ACTION_VIEW action and a URI containing the coordinates. Then, using setPackage, we explicitly specify that we want to use Google Maps (though this is optional — the system may offer a choice). The most important part is the check via resolveActivity. This prevents a crash if the required app is not present on the device.
Scenario: Calling the Camera and Getting a Result
\n\nNow let's move to a more complex case — launching an Activity from another app and expecting a result. A classic example: taking a photo and receiving it in your app.
\n\n// Kotlin\nprivate const val REQUEST_IMAGE_CAPTURE = 1\n\nprivate fun dispatchTakePictureIntent() {\n val takePictureIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)\n // Check that the camera is available\n if (takePictureIntent.resolveActivity(packageManager) != null) {\n startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE)\n } else {\n // Handle error: camera not found\n }\n}\n\noverride fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {\n super.onActivityResult(requestCode, resultCode, data)\n if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {\n val imageBitmap = data?