2010-10-28 16 views
11

Uygulamamın yeni bir örneğini başlatmak yerine uygulamanızı RESUME uygulamasına programlamaya çalışıyorum ... Ana düğme uzun basıldığında ve uygulamada olduğu gibi aynı şeyi yapmak için temelde arıyorum. oradan devam edilir. İşteAndroid: Bir Bildirimin Uygulamasını Nasıl Sürdürebilirim?

Şu anda ne yapıyorum geçerli:

void notifyme(String string){ 

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

    int icon = R.drawable.notification_icon;  // icon from resources 
    CharSequence tickerText = string + " Program Running...";  // ticker-text 
    long when = System.currentTimeMillis();   // notification time 
    Context context = getApplicationContext();  // application Context 
    CharSequence contentTitle = *********; // expanded message title 
    CharSequence contentText = string + " Program Running...";//expanded msg text 

    Intent notificationIntent = new Intent(this, Main.class); 
    PendingIntent contentIntent = PendingIntent.getActivity(
               this, 0, notificationIntent, 0); 

    // the next two lines initialize the Notification, using the configurations 
    // above 
    Notification notification = new Notification(icon, tickerText, when); 
    notification.setLatestEventInfo(context, contentTitle, contentText, 
                   contentIntent); 
    final int HELLO_ID = 1; 
    mNotificationManager.notify(HELLO_ID, notification); 
} 

Sorun burada yatıyor ... herhangi bir yardım mutluluk duyacağız yeni Niyet çizgi olduğunu tahmin ediyorum! Hiç bir yinelenen etkinlik için olmak istiyorum asla eğer

+0

olası kopyalarda o bu niteliği vermek,

notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.FLAG_NO_CLEAR; notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 

Ayrıca bayraklarını ayarlamanız gerekir: http: // stackoverflow.com/questions/5502427/resume-application-and-stack-from-notification, http://stackoverflow.com/questions/3356095/how-to-bring-android-existing-activity-to-front-via- Bildirim – Philipp

+0

bu bana yardımcı oldu http://stackoverflow.com/questions/3305088/how-to-make-notification-intent-resume-rather -Tan-a-yeni-niyet/39482464 # 39482464 – TharakaNirmana

cevap

12

Eğer tezahür

android:launchMode="singleTask" 
+0

Bu sadece uygulama Ana Düğme ile çıkıldığında çalışır ... ama geri düğmesi ile uygulamadan çıkıldığında işe yaramaz ... herhangi bir fikir nasıl bunu tamir et??? –

+0

bildirimlerinizde, devam etmekte olduğunuzu belirtmek için eylemi ayarlayın, bu eylemi yeniden oluşturun ve buna göre davranın, – schwiz

+1

Yönergesi'nde bir paket içinde düzgün şekilde geri yüklemek için gereken verileri iletin. @FrankBozzo'nun yorumu: varsayılan davranış, geri düğmesi üzerindeki etkinliği kapatmak/yok etmektir (bu en azından 'adb logcat'nın bana söylediği şey) - böylece öldürülen bir etkinliğe devam edemezsiniz ... Uygulamadan çıkmak için varsayılan geri düğmesi davranışını geçersiz kıl (bkz. 'WebChromeClient' olayları). – Philzen

İlgili konular