Skip to content

Commit d3b8b10

Browse files
committed
Fix reliability of file association on Android
1 parent 4d33da8 commit d3b8b10

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

platform/android/AndroidManifest.xml.in

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@
5353
android:theme="@style/AppTheme">
5454
<activity
5555
android:name="ch.opengis.@[email protected]"
56+
android:taskAffinity="ch.opengis.@APP_PACKAGE_NAME@"
57+
android:launchMode="singleInstance"
58+
android:allowTaskReparenting="false"
59+
android:documentLaunchMode="never"
60+
android:alwaysRetainTaskState="true"
61+
android:clearTaskOnLaunch="false"
5662
android:label="@APP_NAME@"
5763
android:icon="@AT@drawable/@APP_ICON@"
58-
android:launchMode="singleTask"
5964
android:configChanges="orientation|uiMode|screenLayout|screenSize|smallestScreenSize|locale|fontScale|keyboard|keyboardHidden|navigation"
6065
android:theme="@style/AppTheme"
6166
android:exported="true">
67+
6268
<intent-filter>
6369
<action android:name="android.intent.action.MAIN"/>
6470
<category android:name="android.intent.category.LAUNCHER"/>
@@ -93,7 +99,7 @@
9399
<intent-filter>
94100
<action android:name="android.intent.action.VIEW" />
95101
<category android:name="android.intent.category.DEFAULT" />
96-
<category android:name="android.intent.category.BROWSABLE"/>
102+
<category android:name="android.intent.category.BROWSABLE" />
97103
<data android:scheme="file" />
98104
<data android:scheme="content" />
99105
<data android:host="*" />
@@ -115,7 +121,7 @@
115121
<intent-filter>
116122
<action android:name="android.intent.action.VIEW" />
117123
<category android:name="android.intent.category.DEFAULT" />
118-
<category android:name="android.intent.category.BROWSABLE"/>
124+
<category android:name="android.intent.category.BROWSABLE" />
119125
<data android:scheme="file" />
120126
<data android:scheme="content" />
121127
<data android:host="*" />

platform/android/src/ch/opengis/qfield/QFieldActivity.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ public class QFieldActivity extends QtActivity {
127127
public static native void resourceCanceled(String message);
128128

129129
private Intent projectIntent;
130+
130131
private float originalBrightness;
131132
private boolean handleVolumeKeys = false;
132133
private String pathsToExport;
@@ -152,7 +153,12 @@ public void onCreate(Bundle savedInstanceState) {
152153

153154
@Override
154155
public void onNewIntent(Intent intent) {
156+
// Prevent activity restart
157+
intent.setFlags(intent.getFlags() &
158+
~(Intent.FLAG_ACTIVITY_NEW_TASK |
159+
Intent.FLAG_ACTIVITY_NEW_DOCUMENT));
155160
super.onNewIntent(intent);
161+
156162
if (intent.getAction() == Intent.ACTION_VIEW ||
157163
intent.getAction() == Intent.ACTION_SEND) {
158164
projectIntent = intent;
@@ -522,8 +528,11 @@ private void prepareQtActivity() {
522528
}
523529
}
524530

525-
Intent intent = new Intent();
531+
Intent intent = new Intent(Intent.ACTION_VIEW);
526532
intent.setClass(QFieldActivity.this, QtActivity.class);
533+
// Prevent activity restart
534+
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
535+
Intent.FLAG_ACTIVITY_SINGLE_TOP);
527536
try {
528537
ActivityInfo activityInfo = getPackageManager().getActivityInfo(
529538
getComponentName(), PackageManager.GET_META_DATA);
@@ -548,6 +557,7 @@ private void prepareQtActivity() {
548557
projectIntent = sourceIntent;
549558
intent.putExtra("QGS_PROJECT", "trigger_load");
550559
}
560+
551561
setIntent(intent);
552562
}
553563

0 commit comments

Comments
 (0)