Уведомление: передать данные - PullRequest
2 голосов
/ 31 октября 2010

Я пытаюсь передать данные из уведомления в активность:

btnShedule.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

            Intent notificationIntent = new Intent(Oconf.this, Oconf.class);
            notificationIntent.putExtra("test", 122);

            PendingIntent contentIntent = PendingIntent.getActivity(Oconf.this, 0, notificationIntent, 0);

            Notification notification = new Notification(R.drawable.notify_deal, "text", System.currentTimeMillis());
            notification.setLatestEventInfo(Oconf.this, getString(R.string.notify_events), "text", contentIntent);

            notification.defaults |= Notification.DEFAULT_SOUND;
            notification.flags |= Notification.FLAG_AUTO_CANCEL;

            notificationManager.notify(0, notification);
        }
    });

Затем onResume:

public void onResume() {

    String q = getIntent().getStringExtra("test");
    if (q == null) {
        Log.e(TAG, "null!");
    }
    else {
        Log.e(TAG, q);
    }

    super.onResume();
}

Я получил "null!".Где ошибка?

Ответы [ 2 ]

3 голосов
/ 28 сентября 2011

В моем случае onNewIntent() никогда не вызывался, когда я нажимал на уведомление.Однако я добавил следующий код в метод onCreate():

String m = getIntent().getStringExtra("put_extra_string");

и получил строку, которую пытался передать в намерение уведомления.

2 голосов
/ 31 октября 2010

:)

protected void onNewIntent(Intent intent)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...