objc3p0
objc3p0

Reputation: 1

Start main activity when opening backgrounded app from other app by url scheme

I've just implemented deep linking to my app. I've added intent filter to my main activity. When user starts my url scheme I'm parsing it and handling in the activity to display proper information depending on parameters. It works well when my app is started from scratch.

    <activity
    android:launchMode="singleTask"
    android:name="com.my.app.ui.activities.MainActivity"
    android:screenOrientation="portrait"
    android:configChanges="orientation|screenSize|">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="myapp-scheme"/>
    </intent-filter>
</activity>

The problem occurs when user opens some other activities on stack and goes background. Now if this app is resumed from background by calling my scheme url, all activities are still on the stack and the main activity doesn't show up. How can I resolve this? I think about navigating back to the main activity, but I don't have info if app was started from other app or in the normal way.

Upvotes: 0

Views: 486

Answers (1)

Gautami Bhandary
Gautami Bhandary

Reputation: 51

You need to make your MainActivity as singleTask by adding following line in the manifest(for ManiActivity):

android:launchMode="singleTask"

Then, override the onNewIntent() in the MainActivity and handle the navigation based on deep link data.Hope this answers your question.

Upvotes: 1

Related Questions