通知点击显示独特的数据问题 [英] Notification Click display unique data issue

查看:151
本文介绍了通知点击显示独特的数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<一个href=\"http://stackoverflow.com/questions/31836529/not-able-to-identify-id-for-item-clicked-on-notification/31836754#31836754\">Not能够识别ID为项目点击通知是唯一的ID这是工作顺利,现在同样的,即使不同的ID当我点击通知我得到唯一的发票编号,其中我传递到web服务得到它的发票明细,尽管它对于id获取数据时,itemActivity页面只显示previous细节,我怎么会用新的内容更新页面?

Not able to identify id for item clicked on notification was for unique id which is working out well,now for the same even with different id when i click on notifications i get unique invoice id ,which i am passing to a webservice to get its invoice details,even though its fetching data for that id,the itemActivity page is showing previous details only,how will i update the page with new contents ?

发送通知code是

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我读数据,如

and itemActivity i am reading data like

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");
}

它就像当我们出来的应用程序,然后单击第二个通知,它只是淡淡地表示previous之一的发票明细,德是没有呼叫正在进行获取的点击。数据

its like when we come out of the application and click on second notification,its just blandly showing the invoice details of previous one,der is no call going on to fetch data for clicked on.

推荐答案

当你在你的的PendingIntent FLAG_ACTIVITY_SINGLE_TOP 标志C>还必须实现在 ItemActivity onNewIntenet()的方法来妥善处理这一发射方式。按<一个href=\"https://developer.android.com/reference/android/app/Activity.html#onNewIntent(android.content.Intent)\"相对=nofollow>文档:

As you are using FLAG_ACTIVITY_SINGLE_TOP flag in your PendingIntent you must also implement onNewIntenet() method in ItemActivity to properly handle this launch mode. As per documentation:

这是呼吁,在设置launchMode为singleTop的活动
  其包装,或者如果所使用的客户端FLAG_ACTIVITY_SINGLE_TOP标志
  调用startActivity时(意向)。在这两种情况下,当活动
  的同时在活动堆栈顶部重新发起一个新的代替
  被启动的活动的情况下,onNewIntent()将被称为
  与被用来意图重新启动现有的实例
  吧。

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.

这是活动总是会接收到一个新的意图之前已暂停,此时
  你可以指望onResume()被调用此方法后。

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

注意getIntent()仍返回原来的意图。您可以使用
  setIntent(意向)将其更新到这个新的意图。

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

所以应该足以从你的 onResume()和限制 onNewIntent()实施单一 setIntent()电话。

so it should be sufficient to move some code from your onResume() and limit onNewIntent() implementation to single setIntent() call.

这篇关于通知点击显示独特的数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆