https://kotlinlang.org logo
#android
Title
# android
b

budioktaviyan

08/28/2017, 10:36 AM
It is throws an exception like this
Only static methods can be annotated with @DeepLink
g

gildor

08/28/2017, 10:39 AM
@budioktaviyan Please, show your code. Probably you annotated class method with this annotation.
Try to annotate top level function or move function to companion object and add
@JvmStatic
annotation
b

budioktaviyan

08/28/2017, 10:41 AM
Copy code
@DeepLink(SCHEME.plus(SERVICE_PAYMENT))
fun registerServiceDeepLink(context: Context): Intent {}
g

gildor

08/28/2017, 10:41 AM
Please show more code, it’s just a function declaration
b

budioktaviyan

08/28/2017, 10:41 AM
I just create this in my class, but suddenly it throws the exception. Previously it was Java class with static function
g

gildor

08/28/2017, 10:42 AM
As I said, if you need static method, you have two options, I mentioned them above
Kotlin has no static function, you should use top level function (function outside class) or function inside companion object with
@JvmStatic
annotation
b

budioktaviyan

08/28/2017, 10:43 AM
Yes, I ever do that but it is not working
wait, I will share the complete code
Copy code
class DeepLinkDispatcher {

    companion object {
        const val SERVICE_PAYMENT = "payment"
        const val SCHEME = "myweb://"
        const val FLAGS_NEW_TASK = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_SINGLE_TOP

        @DeepLink(SCHEME.plus(SERVICE_PAYMENT))
        @JvmStatic
        fun registerServiceDeepLink(context: Context): Intent {
            return Intent(context, clazz<PaymentHomeActivity>()).apply {
                putExtra(PaymentHomeActivity.HomeIntentKey.SOURCE, MyConstants.EventConstants.PROPERTY_VALUE_SOURCE_DEEP_LINK)
                action = DeepLinkKey.ACTION_DEEP_LINK_SERVICE
                flags = FLAGS_NEW_TASK
            }
        }
    }
}
g

gildor

08/28/2017, 10:49 AM
Oh, yeah, I see, probably it will not work, just because JvmStatic generates one more method, not replaced original one. Maybe better to use top level function
b

budioktaviyan

08/28/2017, 10:50 AM
I have been do this but it is not working for this lib 😄
hmmm ic
g

gildor

08/28/2017, 10:50 AM
I’m not sure about my previous statement, but probably it works this way
b

budioktaviyan

08/28/2017, 10:50 AM
let me try
g

gildor

08/28/2017, 10:51 AM
Anyway, top level functions is definetely static
b

budioktaviyan

08/28/2017, 10:52 AM
yeah, I know it :) .. cool its working now
g

gildor

08/28/2017, 10:53 AM
I’ve checked. Yes, @JvmStatic creates one more method for Java, that proxies call to Companion object, so this lib found also non-static version
Actually it’s interesting case, maybe you should create an issue about it, and someone would propose some solution also for such cases, but probably top level function is good workaround for all cases, I’m not sure
b

budioktaviyan

08/28/2017, 10:56 AM
yes, I will raised an issue on those lib ASAP 🙂
g

gildor

08/28/2017, 10:57 AM
Anyway, this lib does everything in correct way, but probably they could add some Kotlin workaround and docs
b

budioktaviyan

08/28/2017, 10:58 AM
and did you know ? this lib are really helpfull for create a simple deeplink in android hahaha
a

alex.hart

08/28/2017, 11:01 AM
This would make a great medium post, exploring the compile-time differences between @JVMStatic annotated methods and top-level methods.. because I can guarantee other people will be bitten by this (I learned something today!)
b

budioktaviyan

08/28/2017, 11:41 AM
Yes, me too, Just know it. Sometimes it can be a little bit different between top-level function and
@JVMStatic
hahahha
2 Views