gpt4 book ai didi

android - 单击通知时恢复 Activity

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:57:15 24 4
gpt4 key购买 nike

我制作了一个管理短信的应用程序,我已经创建了通知,但是当我点击它们时它会启动另一个 Activity ,我想知道如何检查一个 Activity 是否已停止并恢复它。

这是用于创建 pendingintent 的代码:

private void createNotification(SmsMessage sms, Context context){

final NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

String contentTitle = "";


// construct the Notification object.
final NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(contentTitle)
.setContentText(sms.getMessageBody())
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(getIconBitmap())
.setNumber(nmessages);

builder.setAutoCancel(true);

//(R.drawable.stat_sample, tickerText,
// System.currentTimeMillis());

// Set the info for the views that show in the notification panel.
//notif.setLatestEventInfo(this, from, message, contentIntent);
/*
// On tablets, the ticker shows the sender, the first line of the message,
// the photo of the person and the app icon. For our sample, we just show
// the same icon twice. If there is no sender, just pass an array of 1 Bitmap.
notif.tickerTitle = from;
notif.tickerSubtitle = message;
notif.tickerIcons = new Bitmap[2];
notif.tickerIcons[0] = getIconBitmap();;
notif.tickerIcons[1] = getIconBitmap();;
*/

// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, BasicActivity.class);

resultIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
// Because clicking the notification opens a new ("special") activity, there's
// no need to create an artificial back stack.
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
context,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT
);


// Ritardo in millisecondi



builder.setContentIntent(resultPendingIntent);

nm.notify(R.drawable.ic_drawer, builder.build());

最佳答案

您需要在 PendingIntent 中设置标志...例如 FLAG_UPDATE_CURRENT。

一切尽在这里。 http://developer.android.com/reference/android/app/PendingIntent.html

编辑 1:我误解了这个问题。

以下是具有相同问题但已解决的主题的链接:

resuming an activity from a notification

Notification Resume Activity

Intent to resume a previously paused activity (Called from a Notification)

Android: resume app from previous position

请阅读以上答案以获得完整的解决方案,如果可行请告诉我。

关于android - 单击通知时恢复 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19163367/

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