| |||||||
Das Thema "Service startet Activity mehrfach" befindet sich unter Android App Entwicklung auf Android-Hilfe.de.
|
| | Themen-Optionen | Ansicht |
| | #1 (permalink) |
| Neuer Benutzer Registriert seit: 24.05.2011
Beiträge: 1
Abgegebene Danke: 0
Erhielt 0 Danke für 0 Beiträge
| 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);
} Gruß Marlon |
| | |
| | #2 (permalink) |
| Android Experte |
Im Android Manifest musst du android:launchMode="singleTask" im Activity Tag hinzufügen, dann wird es nur einmal ausgeführt.
__________________ G-MoN Wardriving Tool für Android G-MoN auf Twitter |
| | |
![]() |
|
| Themen-Optionen | |
| Ansicht | |
| |
| ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| Service soll Activity benachrichtigen, wie? | tar | Android App Entwicklung | 4 | 09.03.2011 20:56 |
| Service startet erst nach onCreate bzw. onResume in Activity | dronox | Android App Entwicklung | 3 | 23.11.2010 09:24 |
| Kommunikation von Service auf Activity ! | KianS | Android App Entwicklung | 3 | 04.10.2010 17:24 |
| Activity nicht mehrfach öffnen | foxyyy | Android App Entwicklung | 22 | 23.08.2010 19:26 |
| Bidirektionale Kommunikation zwischen Activity und Service | dereulenspiegel | Android App Entwicklung | 0 | 20.11.2009 13:19 |