The Problem
Android applications, when launched from the home screen will display a particular activity which you will usually want to be your application. However, in the case of Auth Connect and a user logging into the application the activity they want to go back to is the login browser window rather than your application.
The Solution
The solution for this issue is likely to be fixed for Cordova with a change to the Auth Connect plugin expected in October 2021. For Capacitor projects or where the problem needs to be resolved urgently the following steps are necessary.
Create a new Activity
In your Android Studio project create a new Activity with the following definition.
package io.ionic.demoapp.ionifits;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class LauncherActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (isTaskRoot()) {
Intent i = new Intent(this, MainActivity.class);
startActivity(i);
}
finish();
}
}
Update AndroidManifest.xml
Update the AndroidManifest.xml file to set the new Activity as the launcher activity, and keep the MainActivity launchMode as singleTask.
Make sure to remove the intent-filter on the MainActivity that defines it as the launcher.
<activity android:name="io.ionic.demoapp.ionifits.LauncherActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBarLaunch">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
android:name="io.ionic.demoapp.ionifits.MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="ionifits" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/*"/>
</intent-filter>
</activity>
Comments
0 comments
Please sign in to leave a comment.