收到通知后,由于 Android 中的后台限制,Activity 无法启动
如何检查我是否可以通过代码调用startActivity而无需try catch块 https://developer.android.com/guide/components/activities/background-starts
使用包管理器
Intent intent = new Intent(this, YourTargetActivity.class);
// Check if there is at least one activity that can handle the intent packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
if (!activities.isEmpty()) {
// There's at least one activity that can handle this intent, so it's safe to start it
startActivity(intent);
} else {
// No activity can handle the intent, handle this case as needed (e.g., show an error message)
}