Android Q特性之后台启动Activity限制
从Android Q版本开始,google为了让用户有更好的使用体验,限制后台App启动Activity,以防止打扰当前用户操作。
对于即时通讯、需要用户马上应答等场景,如视频、音频Call,google给出的建议是使用Full Screen Intent Notification。代码如下:
String title ="Title";
String content ="Content";
Intent fullScreenIntent =new Intent(this, MainActivity.class);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
fullScreenIntent.putExtra("action", "action");
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0, fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, id)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(title)
.setTicker(content)
.setContentText(content)
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(Notification.CATEGORY_CALL)
.setFullScreenIntent(fullScreenPendingIntent, true);
notificationBuilder.build();
google官方文档参考链接:https://developer.android.google.cn/guide/components/activities/background-starts
网友评论