2016-05-04 14 views
0

Ich möchte meine Timer-App öffnen, wenn ich auf die Benachrichtigung klicke. Ich habe den untenstehenden Code bereits ausprobiert, aber dann beginne ich einfach eine neue Aktivität. Ich möchte die Aktivität starten, die bereits ausgeführt wird.Wie öffne ich eine laufende Aktivität mit einer Benachrichtigungsaktion?

Intent intent = new Intent(timer.this, timer.class); 
PendingIntent pIntent = PendingIntent.getActivity(timer.this, 0, intent, 0); 

notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
notification = new Notification.Builder(timer.this) 
         .setSmallIcon(R.mipmap.ic_launcher) 
         .setContentIntent(pIntent) 
         .setContentTitle(clickedinterval) 
         .setContentText("Pause" + " Time remaining: " + minutesPauseCountDown + ":" + secondsPauseCountDown) 
         .build(); 

notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.DEFAULT_LIGHTS; 

notificationManager.notify(0, notification); 
+0

eine Frage in Bezug auf die coding- warum halten Sie die Java-Klassennamen mit Kleinbuchstaben versuchen können? –

Antwort

0
in your case use android:launchMode="singleInstance" in mainfest file 
Or 
Intent.FLAG_ACTIVITY_NEW_TASK 


<activity android:name=".Timer" android:label="@string/app_name" 
       android:launchMode="singleTop" /> 

auch

Intent intent = new Intent(Timer.this, Timer.class); 
       intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); 
       PendingIntent pIntetn = PendingIntent.getActivity(timer.this, 0, intent, 0); 

       notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
       notification = new Notification.Builder(timer.this) 
         .setSmallIcon(R.mipmap.ic_launcher) 
         .setContentIntent(pIntetn) 
         .setContentTitle(clickedinterval) 
         .setContentText("Pause" + " Time remaining: " + minutesPauseCountDown + ":" + secondsPauseCountDown) 
         .build(); 

       notification.flags = Notification.FLAG_ONGOING_EVENT | Notification.DEFAULT_LIGHTS; 

       notificationManager.notify(0, notification); 
+0

eine Frage bezüglich der Codierung- warum behalten Sie den Namen der Java-Klasse mit kleinen Buchstaben? Sorry Die Frage war für den Hauptmann –

+0

, der nicht funktioniert hat –

Verwandte Themen