Skip to content

Commit 7c07ddc

Browse files
committed
android: Fix issue where another instance of app would start on sharing.
This would occur whenever zulip was started by another Activity using startActivityForResult. Ideally with launchMode="singleTask" zulip should always launch in a seperate task, this however is not the case, when it is started via startActivityForResult by another app. With startActivityForResult another instance of zulip would be initialized inside the calling app, regardless of the fact that zulip was in background or not. This caused problems especially for share to zulip intents and this commit addresses those cases. Now SEND intent is not captured by MainActivity, a seperate native activity is created to capture them and it redirects the intents unchanged to MainActivity by calling startActivity, hence always ensuring that zulip is launched as a seperate task. (If zulip was already running and in background, it will be used instead of creating a new task.)
1 parent ee02551 commit 7c07ddc

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
android:host="login"
4545
android:scheme="zulip" />
4646
</intent-filter>
47+
</activity>
48+
49+
<activity
50+
android:name=".HandleSendIntent"
51+
android:label="@string/app_name"
52+
android:launchMode="standard"
53+
>
4754
<!-- Disabled while the feature is experimental. See #117 and #4124.
4855
<intent-filter>
4956
<action android:name="android.intent.action.SEND" />
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.zulipmobile;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.app.Activity;
6+
import android.content.Intent;
7+
import android.content.ComponentName;
8+
import android.content.pm.PackageManager;
9+
import android.os.Bundle;
10+
import android.util.Log;
11+
import android.widget.TextView;
12+
13+
class HandleSendIntent : AppCompatActivity() {
14+
override fun onCreate(savedInstanceState : Bundle?) {
15+
super.onCreate(savedInstanceState)
16+
intent.component = ComponentName(applicationContext.packageName, "com.zulipmobile.MainActivity")
17+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
18+
startActivity(intent)
19+
finish()
20+
}
21+
}

0 commit comments

Comments
 (0)