receive_sharing_intent icon indicating copy to clipboard operation
receive_sharing_intent copied to clipboard

New activity instance opened on Android 11

Open krille-chan opened this issue 5 years ago • 5 comments

Thank you very much for your awesome package. In my app I have implemented this with android:launchMode="singleTask" and this worked quiet well all the time. Unfortenetly on Android 11 this doesn't work anymore. On Android 11 a new instance of the Flutter activity is opened which leads to problems.

Does anyone knows a workaround so far?

Best regards and stay healthy

krille-chan avatar Dec 01 '20 12:12 krille-chan

I am facing the same issue. Did you find any workaround so far?

lateralus69 avatar Dec 06 '20 12:12 lateralus69

I am using Android 9 for testing and getting same issue only when sharing from some apps like Telegram It is working fine with the apps like instagram, facebook etc

gauravsmishra avatar Mar 02 '21 17:03 gauravsmishra

make sure you add the following part correctly image

elham-rababah avatar Apr 15 '21 18:04 elham-rababah

@elham-rababah That looks like it might solve the issue. Would you mind giving some more background on what the code snippet does and why?

EDIT: I dug into this some more. Actually the entry in AndroidManifest.xml should be enough to make sure that only one instance of your app is launched. here is some more background on that.

The code snippet is meant to ensure that your app's activity is not launched on top of the app that the user is sharing from (to the user seemingly replacing it). According to this this SO question however, the code above is only applicable specifically when sharing from Google Chrome. In the general case, the snippet you want is:

import android.app.Activity
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import android.os.Bundle

class ExternalTextReceiverActivity : Activity() {
    val CUSTOM_EXTRA_NAME = "RELAUNCHED"

    override fun onCreate(savedInstanceState: Bundle?) {
        if (!intent.getBooleanExtra(CUSTOM_EXTRA_NAME, false)) {
            this.finish()
            intent.addFlags(FLAG_ACTIVITY_NEW_TASK);
            intent.putExtra(CUSTOM_EXTRA_NAME, true);
            startActivity(intent);
        }
        super.onCreate(savedInstanceState);
        // The rest of your onCreate code here

    }
}

I have not testet this myself yet.

tjarvstrand avatar May 07 '21 07:05 tjarvstrand

same problem on Android 10 also with outlook. the suggestion from elham-rababah do not work for me. Any other suggestions?

klausszilvas avatar Jul 19 '21 15:07 klausszilvas