2016-04-11 13 views
0

Ich weiß, es gibt zahlreiche Fragen dazu, aber sie haben mir nicht geholfen. Irgendwann erstellt meine App eine Benachrichtigung und ich möchte, dass sie die aktuelle App an die Front bringt, ohne eine neue zu erstellen.Android: Bring aktuelle Aktivität nach vorne über die Benachrichtigung

My-Code (innen MainActivty):

Intent intent = new Intent(this,MainActivity.class); 
    intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0); 
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this) 
      .setSmallIcon(R.mipmap.ic_launcher) 
      .setContentTitle("Titel") 
      .setContentText("Text") 
      .addAction(new NotificationCompat.Action(R.mipmap.ic_launcher, "Testtitel", 
        pendingIntent)); 
    NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    manager.notify(0,builder.build()); 

die Notification-korrekt dargestellt, aber darauf klicken hat keine Auswirkung. Was mache ich falsch?

+0

Wann immer eine Benachrichtigung empfangen wird Sie die Seite auf eine Tätigkeit übertragen Intents –

+0

mit i habe es mit '.setContentIntent (pendingIntent);' anstelle von 'addAction' gearbeitet – Ginso

Antwort

0

Ich verwende Benachrichtigung in meiner Anwendung und wenn eine bestimmte Benachrichtigung empfangen wird ich meine Tätigkeit direkt wie das Öffnen unter

 if (notification_type.equalsIgnoreCase("3")) { 
        Log.d(TAG, "Notification: " + "Before Meeting"); 

        PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); 
        PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK 
          | PowerManager.ACQUIRE_CAUSES_WAKEUP 
          | PowerManager.ON_AFTER_RELEASE, "MyWakeLock"); 
        wakeLock.acquire(); 
        KeyguardManager km = (KeyguardManager) getApplicationContext().getSystemService(Context.KEYGUARD_SERVICE); 
        final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("MyKeyguardLock"); 
        kl.disableKeyguard(); 

         Intent intentToMain = new Intent(this, MainActivity.class); 
         intentToMain.putExtra("destroy", "destroy"); 
         intentToMain.addFlags(intentToMain.FLAG_ACTIVITY_NEW_TASK); 
         startActivity(intentToMain); 

       } 
Verwandte Themen