-1

通知インテントからアクティビティの 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() には次のコードがあります -

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

このコードでは、通知コードから値 4 を送信した場合でも、Log.i は値 0 を返します。どこが間違っているのか教えてください。他に詳細が必要な場合はお知らせください。

ありがとう、レイ

4

1 に答える 1

0

データを取得するために使用しているキーを確認してください。設定するときは定数変数を使用しますが、取得するときはハードコードされた文字列を使用します。それを台無しにするのは簡単です。

于 2012-10-28T14:55:47.267 に答える