4

1/如果这个应用程序已经在前台运行我的应用程序,我不想通知用户,
是否可以在创建通知之前检查我的应用程序是否不在前面?

2/如果应用程序在后台,是否可以将最后一个状态放在前面?
我知道os可以销毁一些Activity,但是有没有可能恢复上一个状态,不要启动一个新的Intent?
因为如果我开始一个新的 Intent 并且我推回,旧的 Intent 似乎有 2 个相同的 Intent 启动不是很漂亮。

谢谢

NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
Intent notificationIntent = new Intent(this, z_finish.class);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification = new Notification(icon, tickerText, when);
notification.flags |= Notification.FLAG_AUTO_CANCEL;

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
final int HELLO_ID = 1;
mNotificationManager.notify(HELLO_ID, notification); 
4

2 回答 2

2

在创建通知之前是否可以检查我的应用程序是否不在前面?

您的活动必须在暂停和恢复时通知服务;然后服务可以决定是否显示Notification

如果应用程序在后台,是否可以将最后一个状态放在前面?

我不太确定“最后状态”是什么。试试FLAG_ACTIVITY_CLEAR_TOP你的Intent.

于 2010-08-06T09:32:40.410 回答
0

如果您的应用程序处于单任务模式,那么即使您重新启动它也会保存最后一个状态

于 2010-08-27T13:49:13.093 回答