androidandroid-intent

Doesn't navigate back to app when clicking back from PDF intent


Hello I am using the below code in Compose and can't seem to figure out why when I open a PDF, then click back it takes me to the home screen and not my app. Does anyone know if there's anything I'm missing? I've looked for a few days now and can't seem to find anything helpful..

private fun openFileWithIntent(context: Context, file: File, mimeType: String) {
        val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)
        val intent = Intent(Intent.ACTION_VIEW).apply {
            setDataAndType(uri, mimeType)
        }
        intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION

        try {
            context.startActivity(intent)
        } catch (e: ActivityNotFoundException) {
            e.printStackTrace()
        }
}

Solution

  • I needed to take this line out of the manifest for the activity starting the PDF viewer

    android:noHistory="true"