Android: когда нажимается уведомление, как вернуться к тому же приложению?

Я знаю, что название не является пояснительным, но позвольте мне объяснить его вам. Я работаю над проектом потокового радио Shoutcast. Когда приложение начинает потоковую передачу, на панели уведомлений появляется уведомление с названием радио и текущим идентификатором песни. Пока все выглядит нормально, однако, когда пользователь касается уведомления (пока поток продолжается), он снова открывает приложение, и начинает воспроизводиться другой поток. Надеюсь, я хорошо объяснил проблему, и вот код:

РЕДАКТИРОВАТЬ:

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

person user2604150    schedule 21.07.2013    source источник


Ответы (1)


См. код. Мне это помогает.

    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);
person Community    schedule 21.07.2013