Service startet Activity mehrfach

M

Marlon

Neues Mitglied
0
Hallo,

Ich habe in meinem Programm einen Service laufen, der während er läuft eine Statusleistenbenachrichtigung anzeigt.
Klickt man darauf, soll die Activity zum Menü des Programms wieder gestartet werden, bzw falls sie schon läuft, soll diese wieder in den Vordergrund.
Mein Problem ist nun Zweiteres. Falls die Activity schon im Vordergrund ist, so wird sie dennoch ein weiteres mal gestartet und läuft nun doppelt (bemerkbar über den "zurück" Button).

Mein Code:
Code:
    private void createStatusBarIcon()
    {
        String ns = Context.NOTIFICATION_SERVICE;
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
        int icon = R.drawable.icon;
        CharSequence tickerText = "Ticker";
        long when = System.currentTimeMillis();

        Notification notification = new Notification(icon, tickerText, when);
        Context context = getApplicationContext();
        CharSequence contentTitle = "Content";
        CharSequence contentText = "Contenttext";
        Intent notificationIntent = new Intent(this.getApplicationContext(), MenuActivity.class);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
        notification.flags |= Notification.FLAG_ONGOING_EVENT;

        notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
        
        mNotificationManager.notify(HELLO_ID, notification);
    }
Wie kann ich das gewünschte Verhalten bekommen?

Gruß Marlon
 
Im Android Manifest musst du
android:launchMode="singleTask"
im Activity Tag hinzufügen, dann wird es nur einmal ausgeführt.
 
  • Danke
Reaktionen: DagobertDokate

Ähnliche Themen

M
  • maksimilian
Antworten
15
Aufrufe
1.695
maksimilian
M
M
Antworten
8
Aufrufe
952
deek
D
M
  • maksimilian
Antworten
5
Aufrufe
857
maksimilian
M
Zurück
Oben Unten