I have an application that has an Intent filter to open files of type PDF using it. My app lets users upload the pdf when it's opened with my app within the same logged in session. If a new instance of the app is created, the user has to go through the inconvenience of logging in again.
The issue is that despite having android:launchMode="singleTask" in the Manifest, I arrive at a different instance(Task) of my application when sharing pdf file using certain applications. Ex: If a pdf is shared from FX file explorer app, it opens the pdf in the same instance(desired), but when the same pdf is opened using Google's Files application, it opens as a new Task on top of the existing Files instance.
I have an application that has an Intent filter to open files of type PDF using it. My app lets users upload the pdf when it's opened with my app within the same logged in session. If a new instance of the app is created, the user has to go through the inconvenience of logging in again.
The issue is that despite having android:launchMode="singleTask" in the Manifest, I arrive at a different instance(Task) of my application when sharing pdf file using certain applications. Ex: If a pdf is shared from FX file explorer app, it opens the pdf in the same instance(desired), but when the same pdf is opened using Google's Files application, it opens as a new Task on top of the existing Files instance.
Share Improve this question asked Feb 6 at 6:08 HarshaHarsha 1,7462 gold badges20 silver badges23 bronze badges 3 |1 Answer
Reset to default 0try this:
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!isTaskRoot()) {
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
finish();
return;
} }
singleTask
parameter would suffice – Harsha Commented Feb 6 at 7:04