-
Notifications
You must be signed in to change notification settings - Fork 11
/
DeepLinkForwardingActivity.kt
52 lines (44 loc) · 1.47 KB
/
DeepLinkForwardingActivity.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.authsamples.basicmobileapp.app
import android.app.Activity
import android.content.Intent
import android.os.Bundle
/*
* Use the technique from the below link to prevent the main activity being duplicated during deep linking
* https://labs.comcast.com/deep-linking-through-a-multiple-activity-stack-on-android
*/
class DeepLinkForwardingActivity : Activity() {
/*
* Application startup deep links
*/
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
this.handleIntent(this.intent)
}
/*
* Deep links while the app is running
*/
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
this.handleIntent(intent)
}
/*
* Handle the deep link in a controlled manner
*/
private fun handleIntent(receivedIntent: Intent) {
// If there is a deep link and the main activity is not topmost, ignore it and end this activity
if (!this.app().isMainActivityTopMost()) {
finish()
return
}
// Otherwise activate the main activity and clear this one
receivedIntent.setClass(this, MainActivity::class.java)
receivedIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP)
startActivity(receivedIntent)
}
/*
* Access the application in a typed manner
*/
fun app(): Application {
return this.application as Application
}
}