gpt4 book ai didi

android - 通知点击显示唯一数据问题

转载 作者:行者123 更新时间:2023-11-30 01:58:18 25 4
gpt4 key购买 nike

Not able to identify id for item clicked on notification用于唯一的 id,效果很好,现在即使使用不同的 id,当我单击通知时也一样,我得到了唯一的发票 id,我正在将其传递给 web 服务以获取其发票详细信息,即使它正在获取该 id 的数据,itemActivity 页面仅显示以前的详细信息,我将如何使用新内容更新页面?

发送通知代码为

public class SampleSchedulingService extends IntentService {
public SampleSchedulingService() {
super("SchedulingService");
}
List<GetReminder> newReminderList;
int invoiceId=0;
String remMes;
InvoiceData1 data1;
int InvM_Id;

public static final String TAG = "Scheduling Demo";
// An ID used to post the notification.
public static int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;

@Override
protected void onHandleIntent(Intent intent) {
// BEGIN_INCLUDE(service_onhandle)
// The URL from which to fetch content.
Log.d("MyService", "About to execute MyTask");
//
newReminderList=WebService.invokeGetReminderWS("GetReminder",41);

if(newReminderList!=null){
for(int i=0;i<newReminderList.size();i++) {
sendNotification(newReminderList.get(i).getRemMessage(),newReminderList.get(i).getInvM_Id());
}
}
// Release the wake lock provided by the BroadcastReceiver.
SampleAlarmReceiver.completeWakefulIntent(intent);
// END_INCLUDE(service_onhandle)
}
// Post a notification indicating whether a doodle was found.
private void sendNotification(String msg, int invM_id) {

try {
Intent notificationIntent = new Intent(this, ItemActivity.class);
notificationIntent.setAction(Intent.ACTION_MAIN);
notificationIntent.addCategory(Intent.CATEGORY_LAUNCHER);
data1=WebService.InvoiceDetailForExeedDiscount1(invM_id);
notificationIntent.putExtra("invoiceList", data1);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);

NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(getString(R.string.invoice_alert))
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);

mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
NOTIFICATION_ID++;}
catch (IOException e) {

} catch (XmlPullParserException e) {

}

}

}

和 itemActivity 我正在读取类似的数据

public class ItemActivity extends Activity implements View.OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
final boolean customTitleSupported =
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.itemlist);
if(customTitleSupported){
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.item);
}
InvoiceData1 invoiceList = (InvoiceData1) getIntent().getSerializableExtra("invoiceList");
}

就像当我们从应用程序中出来并点击第二个通知时,它只是平淡地显示前一个通知的发票详细信息,没有调用继续获取点击的数据。

最佳答案

当您在 PendingIntent 中使用 FLAG_ACTIVITY_SINGLE_TOP 标志时,您还必须在 ItemActivity 中实现 onNewIntenet() 方法正确处理此启动模式。根据 documentation :

This is called for activities that set launchMode to "singleTop" in their package, or if a client used the FLAG_ACTIVITY_SINGLE_TOP flag when calling startActivity(Intent). In either case, when the activity is re-launched while at the top of the activity stack instead of a new instance of the activity being started, onNewIntent() will be called on the existing instance with the Intent that was used to re-launch it.

An activity will always be paused before receiving a new intent, so you can count on onResume() being called after this method.

Note that getIntent() still returns the original Intent. You can use setIntent(Intent) to update it to this new Intent.

因此从您的 onResume() 中移动一些代码并将 onNewIntent() 实现限制为单个 setIntent() 调用就足够了.

关于android - 通知点击显示唯一数据问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31854247/

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