2012-10-28 93 views
-1

我正嘗試將一些數據從我的通知意向傳遞給我的一項活動。但不知何故價值沒有得到正確填充。從活動被稱爲地方來自未通知通知的意圖數據

我的通知代碼 -

Long rowId = intent.getExtras().getLong(TasksDBAdapter.KEY_ROWID);     
     // Status bar notification Code Goes here. 

     NotificationManager mgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
     Intent notificationIntent = new Intent(this, ReminderModificationActivity.class); 
     notificationIntent.putExtra(TasksDBAdapter.KEY_ROWID, rowId); 
     Log.i(TAG,"rowId in doReminderWork" + rowId); 
     PendingIntent pi = PendingIntent.getActivity(this, 0, notificationIntent,PendingIntent.FLAG_ONE_SHOT); 

在這段代碼,Log.i值給出正確的ROWID值,但我沒有在ReminderModificationActivity.class得到正確的價值觀。其中的onCreate()由具有的代碼下列片 - 在這種代碼Log.i返回值0,即使我從通知碼發送值4

mRowId = savedInstanceState != null ? savedInstanceState.getLong(TasksDBAdapter.KEY_ROWID) : null ; 
     registerButtonListenersAndSetDefaultText(); 
     Log.i(TAG, "mROwId in onCreate ReminderNotification-->" + getIntent().getExtras().getLong("RowId")); 
     //code to check what row id have been passed 
     if(getIntent() != null) {           
      Bundle extras = getIntent().getExtras();      
      mRowId = extras != null ? extras.getLong("RowId") : -1;  
      // Do stuff with the row id here 
      if(mRowId != -1){ 
       //code if RowId valid 

      } 
     } 
     Log.i(TAG, "mROwId in onCreate ReminderNotification again-->" + mRowId); 

。請致電我,我犯了一個錯誤。讓我知道是否需要其他細節。

感謝, 雷

回答

0

檢查你使用獲得的數據進行的關鍵。當你設置它時,你使用一個常量變量,但是當你得到它時,你使用一個硬編碼的字符串。搞砸這件事很容易。

+0

雅我用了不同的值導致問題。 – RayKaushik