views:

28

answers:

1

I'm trying to pass data from notification to activity:

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

Then, onResume:

public void onResume() {

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

    super.onResume();
}

I got "null!". Where is error?

+1  A: 

:)

protected void onNewIntent(Intent intent)
embo
could you give some example?thank you
pengwang