- Print
Using deep links
- Print
Android Shoplive Player SDK uses various events such as product clicks and notice clicks to switch Shoplive Player to PIP (Picture-in-Picture) mode. It uses the ActivityManager
's getAppTasks()
to find the customer's app task and brings it to the foreground using the moveToFront()
function.
When you open the app by tapping the app icon and Shoplive Player goes into PIP mode, it finds the Launcher Task and brings the customer's app to the foreground during the transition.
However, when you open the app through a deep link, sometimes it may not find the customer's app task, and it cannot bring it to the foreground. This depends on whether the entity executing the deep link used the
Intent.FLAG_ACTIVITY_NEW_TASK
flag during the invocation.
According to the Android deep link documentation, the state of the back stack when triggering an implicit deep link depends on whether the implicit Intent was executed with the Intent.FLAG_ACTIVITY_NEW_TASK
flag.
If the flag is set, the task back stack is cleared, and the deep link target replaces it. Just like with explicit deep links, when nesting the graph, the starting target of each level of nesting, i.e., the starting target of each element in the hierarchy, is added to the stack. So, if the user presses the back button from the deep link target, it navigates back up the navigation stack as if they had entered the app from the entry point.
If the flag is not set, the implicit deep link remains in the task stack of the previous app that triggered it. In this case, pressing the back button will take the user back to the previous app, while pressing the up button will start the app task from the top target within the hierarchy of the navigation graph.
Therefore, if you want Shoplive Player to behave the same way regardless of whether the Intent.FLAG_ACTIVITY_NEW_TASK
flag was applied by the entity executing the deep link, you should implement a separate SchemeActivity responsible for handling deep links and use the Intent.FLAG_ACTIVITY_NEW_TASK
flag when calling the next Activity.
Sample code
shoplive://live?ak={accessKey}&ck={campaignKey}
AndroidManifest.xml
<activity
android:name=".SchemeActivity"
android:exported="true"
android:noHistory="true"
android:screenOrientation="portrait">
<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:host="live"
android:scheme="shoplive" />
</intent-filter>
</activity>
SchemeActivity
class SchemeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
execute(intent)
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
execute(intent)
}
private fun execute(intent: Intent?) {
intent ?: return
val data = intent.data
val accessKey = data?.getQueryParameter("ak") ?: return
val campaignKey = data.getQueryParameter("ck")
if (accessKey.isNotEmpty() && !campaignKey.isNullOrEmpty()) {
// Intent.FLAG_ACTIVITY_NEW_TASK 적용하여 MainActivity 호출
val intent = Intent(this, MainActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
intent.putExtra("accessKey", accessKey)
intent.putExtra("campaignKey", campaignKey)
startActivity(intent)
}
}
}
MainActivity
class MainActivity : AppCompatActivity() {
companion object {
private const val ACCESS_KEY = "accessKey"
private const val CAMPAIGN_KEY = "campaignKey"
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val accessKey = intent.getStringExtra(ACCESS_KEY)
val campaignKey = intent.getStringExtra(CAMPAIGN_KEY)
if (accessKey?.isNotEmpty() == true && campaignKey?.isNotEmpty() == true) {
// Shoplive Player 실행 또는 라이브 페이지 이동하기 구현
}
}
}