GoogleChrome / GoogleChrome/android-browser-helper
onActivityResult not triggering when Activity is started by LauncherActivity
- Dominant language
- Java
- Stars
- 832
- Forks
- 370
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 6
Description
**Describe the bug**
The MyAppLauncherActivity, which is started by the LauncherActivity, does not seem to return a result when it should. However, if I start an activity from a non-launcher activity, it works as expected. Additionally, when the intent for the CameraActivity is inside the main activity, the CameraActivity does not receive the ActivityResult from the camera.
**To Reproduce**
Steps to reproduce the behavior:
1. Launch the application.
2. The MyAppLauncherActivity is started as the launcherActivity.
3. In MyAppLauncherActivity, perform an action that should return a result (e.g., starting CameraActivity).
4. Complete the action in CameraActivity.
5. Expect MyAppLauncherActivity to receive the result, but it doesn't.
**Expected behavior**
MyAppLauncherActivity should receive the result from CameraActivity when it is started from the launcherActivity. Additionally, CameraActivity should receive the ActivityResult when its intent is inside the main activity.
**Did this ever used to work**
No, it has never worked as expected.
**Screenshots**
N/A
**Code Snippets**
MyAppLauncherActivity code:
```kotlin
package me.myapp.core.android
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import com.google.androidbrowserhelper.trusted.LauncherActivity
class MyAppLauncherActivity : LauncherActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent?.data?.let { uri ->
if (uri.scheme == "myapp" && uri.host == "capture-invoice") {
val cameraIntent = Intent(this, CameraActivity::class.java).apply {
data = uri
}
startActivityForResult(cameraIntent, CAMERA_ACTIVITY_REQUEST_CODE)
}
}
}
override fun getLaunchingUrl(): Uri {
val uri = this.intent.data
Log.d("MyAppLog", "Using URL from Intent ($uri).")
if (uri != null) {
return uri
}
return Uri.parse("https://web.acc.myapp.dev")
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
Log.d("MyAppLog", "LauncherActivity - onActivityResult: $requestCode, $resultCode, $data")
if (requestCode == CAMERA_ACTIVITY_REQUEST_CODE && resultCode == RESULT_OK) {
val redirectIntent = Intent(Intent.ACTION_VIEW, Uri.parse("https://web.acc.myapp.dev/received-invoices"))
startActivity(redirectIntent)
}
}
companion object {
private const val CAMERA_ACTIVITY_REQUEST_CODE = 1003
}
}
```
The last piece of code run in the CameraActivy.kt (tested with logs and debugger)
```
setResult(RESULT_OK) // Set the result before finishing
Log.d("MyAppLog", "Image sent to server.")
finish()
```
Manifest
```
```
**Smartphone**
- Device: Samsung Galaxy S10e
- OS: Android 11
- Browsers Installed: Chrome
- android-browser-helper library version: 2.5.0
**Additional context**
- The problem occurs when MyAppLauncherActivity is started from the launcher.
- If MyAppLauncherActivity is started from a non-launcher activity, it works as expected.
- Manifest file includes necessary permissions and intent filters for MyAppLauncherActivity and CameraActivity.
Contributor guide
Assessment
This issue has not been assessed yet.