Можно ли вернуться к предыдущему приложению, откуда ваше приложение открыто? Например, я нахожусь в приложении A, затем я нажимаю на уведомление и открываю свое приложение B, затем в моем приложении BI нажимаю кнопку, и я возвращаюсь к приложению A? В настоящее время я пытаюсь это сделать, и единственный способ добиться этого - это когда мое приложение работает в фоновом режиме или работает только в первый раз.
Я использую Flutter, но эти действия выполняются в собственном Android коде, поэтому я, вероятно, что-то упускаю.
Для возврата к предыдущему приложению я использую: moveTaskToBack(true);
Для создания уведомления мой код выглядит так:
private void NotifyToAutofill(String uri, String url, NotificationManager notificationManager) {
if (notificationManager == null || isNullOrWhitespace(uri)) {
return;
}
Context context = getApplicationContext();
Intent startIntent = new Intent(context, MainActivity.class);
startIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startIntent.setAction(Intent.ACTION_RUN);
startIntent.putExtra("uri", uri);
startIntent.putExtra("url", url.contains("\u2022")
|| url.contains("\u2731") ? "" : url);
String channelId = "channel-01";
String channelName = "test";
int importance = NotificationManager.IMPORTANCE_LOW;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(
channelId, channelName, importance);
notificationManager.createNotificationChannel(mChannel);
}
int color = 0x008000;
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_stat_name)
.setContentTitle("Test Service")
.setContentText("Tap to open application")
.setAutoCancel(true);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(startIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
Notification notification = mBuilder.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(AutoFillNotificationId, notification);
}