2013-07-21 2 views
0

Je sais que le titre n'est pas explicatif mais laissez-moi vous l'expliquer. Je travaille sur un projet de radio en streaming Shoutcast. Lorsque l'application commence à diffuser une notification apparaît sur la barre de notification avec le nom de la radio et l'ID de la chanson en cours. Jusqu'à présent, tout semble normal, mais lorsque l'utilisateur touche la notification (alors que le flux continue), il ouvre à nouveau l'application et un autre flux commence à jouer. J'espère avoir expliqué le problème et bien est le code ici:Android: Lorsque la notification est cliquée comment revenir à la même application?

EDIT:

Hey again, I have just figured out how to make it that way and here is the sample code. 


    String ns = Context.NOTIFICATION_SERVICE; 
    mNotificationManager = (NotificationManager) getSystemService(ns); 

    icon = R.drawable.rbnot; 
    CharSequence tickerText = "Radyo Bilkent"; 
    long when = System.currentTimeMillis(); 

    notification = new Notification(icon, tickerText, when); 
    notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; 
    Intent notificationIntent = new Intent(this, myMain.class); 
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

    Context context = getApplicationContext(); 
    CharSequence contentTitle = "Radyo Bilkent"; 
    CharSequence contentText = currPlayView.getText(); 

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

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 

    mNotificationManager.notify(HELLO_ID, notification); 

Répondre

0

Voir un code. Ça aide pour moi.

NotificationManager notificationManager = (NotificationManager) context 
      .getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification notification = new Notification(icon, message, when); 
    Intent notificationIntent = new Intent(context, HomeActivity.class); 

    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP 
      | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

    PendingIntent intent = PendingIntent.getActivity(context, 0, 
      notificationIntent, 0); 

    notification.setLatestEventInfo(context, title, message, intent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    notificationManager.notify(0, notification); 
+0

Merci pour la réponse, mais cela n'a pas fonctionné pour moi. – user2604150

Questions connexes