J'ai une activité avec quelques édits et un En cours de notification. Après avoir rempli TextTexts, je reviens à l'écran d'accueil en appuyant sur le bouton Accueil (mon application fonctionne en arrière-plan). Tout ce que je veux, c'est revenir à mon activité avec EditTexts rempli (ne pas en créer un nouveau) lorsque je clique sur la notification en cours.Revenir à l'activité précédente lorsque la notification en cours est cliquée
J'ai essayé
How should i do from notification back to activity without new intent
Et ce
Notification click: activity already open
Ils ne fonctionnent pas du tout !!!
Ci-dessous mon extrait de code
ProtocolMonitorActivity.java
Intent resultIntent = new Intent(this, ProtocolMonitorActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(ProtocolMonitorActivity.class);
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notiBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.noti_icon)
.setContentTitle("Protocol Monitor App")
.setContentText("Service is running")
.setOngoing(true);
notiBuilder.setContentIntent(resultPendingIntent);
notiManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notiManager.notify(notiId, notiBuilder.build());
Manifest
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".ProtocolMonitorActivity"
android:label="@string/app_name"
android:process="com.android.phone"
android:launchMode="singleTop"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEVELOPMENT_PREFERENCE" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ProtocolMonitorActivity" />
</activity>
</application>
ce que quelqu'un a une idée à ce sujet?
Merci beaucoup!
Ça a juste marché. Merci pour l'explication de détail !!! –
@ Viet-AnhDinh Salut, le même problème me trouble. Cette méthode fonctionne uniquement lorsque vous fermez votre application. Mais lorsque l'activité est déjà ouverte, elle redémarre. Comment le résoudre sans le mode SingleTask? – AnswerZhao
@AnswerZhao ce n'est pas vrai. Cette solution ramène simplement la tâche existante au premier plan, quel que soit l'état dans lequel elle se trouvait. Elle ne redémarre plus rien. Si vous avez un problème spécifique, vous devriez poster une nouvelle question au lieu de faire un commentaire sur une réponse existante. Cela vous attirera plus d'attention. –