1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Flutter app duplicates in recent apps list when opened via push notification

Discussão em 'Mobile' iniciado por Stack, Outubro 17, 2024 às 12:13.

  1. Stack

    Stack Membro Participativo

    Could someone please help me?

    My app duplicates in the recent apps list when I open it via a push notification. Here’s what happens:

    • I open the app and then close it by pressing the back button.
    • When I receive a push notification and open the app through the notification, it appears twice in the recent apps list.
    • However, if I close the app by pressing the home button after the first start, it works normally.

    I’ve tried using standard, singleTop, singleTask, and singleInstance launch modes, but none of them solved the issue.

    Any advice on how to prevent this duplication in Flutter?

    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
    android:label="Жеке Кабинет Дордой"
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher"
    android:usesCleartextTraffic="true">
    <activity
    android:name=".MainActivity"
    android:exported="true"
    android:launchMode="singleInstance"
    android:taskAffinity=""
    android:theme="@style/LaunchTheme"
    android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
    android:hardwareAccelerated="true"
    android:windowSoftInputMode="adjustResize">
    <!-- Specifies an Android theme to apply to this Activity as soon as
    the Android process has started. This theme is visible to the user
    while the Flutter UI initializes. After that, this theme continues
    to determine the Window background behind the Flutter UI. -->
    <meta-data
    android:name="io.flutter.embedding.android.NormalTheme"
    android:resource="@style/NormalTheme"
    />
    <intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
    This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
    android:name="flutterEmbedding"
    android:value="2" />
    </application>
    <!-- Required to query activities that can process text, see:
    https://developer.android.com/training/package-visibility and
    https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.

    In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
    <queries>
    <intent>
    <action android:name="android.intent.action.PROCESS_TEXT"/>
    <data android:mimeType="text/plain"/>
    </intent>
    </queries>
    </manifest>


    I tried using different launch modes in AndroidManifest.xml, including standard, singleTop, singleTask, and singleInstance. However, none of these modes prevented the app from appearing twice in the recent apps list after being reopened through a push notification.

    I expected the app to appear only once in the recent apps list, regardless of how it was reopened, whether through a push notification or directly from the home screen. Specifically, I expected that setting an appropriate launch mode would ensure that the app resumes the existing instance rather than creating a duplicate.

    Continue reading...

Compartilhe esta Página