Hi guys, any way to extension a class and do the c...
# android
b
Hi guys, any way to extension a class and do the call to itself without any call from class itself ?
r
Can you explain more what's the probl
b
@Rizwan For example, I have a bunch of Fragments. I want to tracking time screen is visited (from viewCreated to viewDestroyed). Anyway to implemented it by extension function without jump to every class to call the function tracking()
l
I think what you’re asking for is to make a type conform to an interface via an extension. I don’t think Kotlin has this feature. Swift does.
j
You can use activity / fragment lifecycle callbacks or register to lifecycle events
b
But the point is no need extra call in every fragment
j
Essentially you could register / unregister the fragment lifecycle callback within your activity lifecycle callback in between activity create and destroy hooks during app initialization in your application or initializer if you use startupx library.
No need to touch any fragment
b
@Jan oh, can you share me a link
j
One implementation have been done the sentry team https://github.com/getsentry/sentry-java/tree/main/sentry-android-fragment which should get you started
b
Thank you. Let me check
l
I would create an abstract MyAppFragment() and make every Fragment of my app extend this fragment. This way you can handle common fragments operations from this one. You'll need to change all your app Fragments superclasses to MyAppFragment, which can make a large commit depending on your codebase, but won't make any difficult conflict
👍 1
1
b
@Loic Teyssier A gree, base Fragment is easy approach. But if the app already in production. Moving all the fragment into child of base class seem impossible right ?
l
I dont understand if your app is in production you still can make the code evolve and publish a new versino later no ?
j
Is tracking really an
is
relationship between parent-/sub fragment?