2010-10-30 4 views
2

Je suis en train de transmettre des données de notification à l'activité:Notification: transmettre des données

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

Puis, onResume:

public void onResume() { 

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

    super.onResume(); 
} 

je suis arrivé "nul!". Où est l'erreur?

Répondre

2

:)

protected void onNewIntent(Intent intent) 
+0

pourriez-vous donner un exemple? Merci – pengwang

+0

http://stackoverflow.com/questions/2845613/intent-putextras-not-consistent/4062693#4062693 – embo

3

Dans mon cas onNewIntent() n'a jamais été appelé quand je tapais sur la notification. Cependant, j'ajouté le code suivant dans la méthode onCreate():

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

et je suis la chaîne que je voulais passer à l'intention de la notification.

Questions connexes