gpt4 book ai didi

android - PendingIntent 不起作用

转载 作者:行者123 更新时间:2023-11-29 17:44:06 25 4
gpt4 key购买 nike

我有一个会显示通知的服务。通知显示正确,但当我点击通知时没有任何反应。它应该在我的应用程序中打开一个 Activity 。这是我的代码:

public class ServiceCheckExpensesRecurring extends Service{

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
int mNotificationId = 001;
Intent myIntent = new Intent(this, MenuDashboard.class);
myIntent.setAction(Intent.ACTION_VIEW);
myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pIntent = PendingIntent.getActivity(getBaseContext(), 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder n = new NotificationCompat.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.common_signin_btn_icon_light)
.setContentIntent(pIntent)
.setAutoCancel(true);

NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

notificationManager.notify(mNotificationId, n.build());
return Service.START_NOT_STICKY;
}
}

仅供引用,MenuDashboard 是一个 fragment (如果有帮助的话)。我正在使用带 ICS 的 sony experia mini

最佳答案

Intent 可以启动Activity(或服务),但不能启动 Fragment。

如果 MenuDashboard 是一个 Fragment,那么它将不起作用。

您应该改用 Activity,并将 Fragment 嵌入其中。

关于android - PendingIntent 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27625018/

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