gpt4 book ai didi

安卓 : switch background process to foreground

转载 作者:行者123 更新时间:2023-11-29 18:03:04 26 4
gpt4 key购买 nike

我的应用程序将创建通知以通知用户

当应用程序在后台运行 8 小时

我想要的只是创建通知(后台)的切换进程

到前台,我该怎么办?

    // PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
// intent, PendingIntent.FLAG_CANCEL_CURRENT);

NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification;

if (Build.VERSION.SDK_INT >= 16) {

Notification.Builder builder = new Notification.Builder(this);
builder.setContentIntent(pendingIntent);
builder.setContentTitle(xx);
builder.setContentText(xx);
builder.setTicker(xx);
builder.setLargeIcon(xx);
builder.setSmallIcon(xx);
builder.setDefaults(Notification.DEFAULT_ALL);
notification = builder.build();

} else {

notification = new Notification(xx, xx, 0);
notification.defaults |= Notification.DEFAULT_ALL;
notification.setLatestEventInfo(this, xx, xx, pendingIntent);

}

enter image description here

enter image description here

谢谢

最佳答案

解决方案

    Intent intent = new Intent(this, StartWorkingActivity2.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

这会将现有任务带到前台,而无需实际创建新 Activity 。如果您的应用程序未运行,它将创建一个 MyRootActivity 实例并启动它。

Bring application to front after user clicks on home button

关于安卓 : switch background process to foreground,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14825879/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com