I am experiencing an issue with opening an app on Android 13. When I use the following code to launch another application, it works fine after rebooting the tablet.
val intent = Intent("android.intent.action.MAIN")
intent.putExtra("fromIntent", true)
intent.setPackage("com.example.myapp")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.putExtra(Constants.DEVICE_TYPE_ID, deviceType)
intent.addCategory("android.intent.category.LAUNCHER")
intent.component = ComponentName("com.example.myapp", "com.example.myapp.MainActivity")
startActivity(intent)
finishAffinity()
However, if I use a different code to launch another application, it doesn't work after a tablet reboot. I am expecting the below code working.
val intent = packageManager.getLaunchIntentForPackage("com.example.myapp")
if (intent != null) {
intent.putExtra("fromIntent", true)
intent.setPackage("com.example.myapp")
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
intent.putExtra(Constants.DEVICE_TYPE_ID, deviceType)
intent.addCategory("android.intent.category.LAUNCHER")
intent.component = ComponentName("com.example.myapp", "com.example.myapp.MainActivity")
startActivity(intent)
finishAffinity()
} else {
Utils.showErrorLog(TAG, "Null Intent")
}
In normal cases, it's working fine. However, the issue was faced after restarting the tablet. Can you please provide a solution why the above code is not working?