Facebook deep linking on Android

前端 未结 3 1418
别那么骄傲
别那么骄傲 2021-02-07 03:01

I\'m trying to implement Facebook\'s Deep Linking feature on my app and encountered the following scenario:

I have an activity called MainActivity which is declared like

相关标签:
3条回答
  • 2021-02-07 03:25

    Facebook is starting your app from their own app by explicitly start your "MainActivity" (the one your provided them in the developer page).

    by that - Android's default behavior is: if the application already runs, then calling again to startActivity() won't start new task from scratch, but only restore to foreground the already running task.

    but the good news are that you can change this default behavior by adding to your MainActivity the android:launchMode="singleTask". it definition is:

    the system creates a new task and instantiates the activity at the root of the new task. However, if an instance of the activity already exists in a separate task, the system routes the intent to the existing instance through a call to its onNewIntent() method, rather than creating a new instance. Only one instance of the activity can exist at a time.

    from this point you could always respond to the starting intent, and from that point you can always navigate back to the task that already was in background(if exists) by restarting activity with both flags Intent.FLAG_ACTIVITY_SINGLE_TOP && Intent.FLAG_ACTIVITY_CLEAR_TOP combination

    0 讨论(0)
  • 2021-02-07 03:34

    See http://developer.android.com/guide/topics/manifest/activity-element.html

    You can play with:

    android:clearTaskOnLaunch
    android:noHistory
    android:launchMode
    
    0 讨论(0)
  • 2021-02-07 03:41

    You need to have more information in your intent filter:

    <intent-filter>
       <action android:name="android.intent.action.VIEW"></action>
       <category android:name="android.intent.category.DEFAULT"></category>
       <category android:name="android.intent.category.BROWSABLE"></category>
       <data android:host="www.yoursite.com" android:scheme="http"></data>
    </intent-filter>
    

    This will capture links going to your site (make sure to change the URL), and direct them to whatever Activity you define this intent filter under.

    0 讨论(0)
提交回复
热议问题