Reading about Android `Context` that is readily av...
# android
v
Reading about Android
Context
that is readily available inside
Activity
and
composable
it says that it should not be passed around or injected. That being said, there are quite a lot of components in Android, such as Bluetooth Adapter, that depend on Context for their instantiation and functionality yet would best be handled outside Activity or a composable and instead be encapsulated in some dedicated Kotlin business domain class. What is the right way to achieve this?
not kotlin but kotlin colored 5
c
Image from iOS.jpg
v
No, it is Kotlin. I am building the class in Kotlin and I am trying to understand how to structure and make it work correctly it with core Android interface
Context
🚫 1
c
Yeah, but your question as you say is about the Android Context and you would have the same issue with a Java class.
So is is not Kotlin specific and should be ask in an Android forum.
v
Yes, but I am not using Java. I am using Android + Kotlin, therefore I have asked the question in
kotlinlang
android
section. Had I used Java I would not have posted the question here
💯 4
🚫 1
👌 1
z
You can pass application context to them Like this
Copy code
Context.getApplicationContext
e
just because you are using Kotlin doesn't make it a Kotlin problem. it's not a Microsoft or Apple problem just because you're using a PC or Mac, is it?
v
Frankly, your reasoning works against you. The fact that this thread is called android is an indication that the problems discussed here will not be purely Kotlin but will be "diluted" with Android related questions. Which would explain a high volume of posts tagged "not kotlin" - people intuitively, and imo rightfully so, assume that if they are developing something for Android OS with Kotlin, this is the right place to ask. At any rate, I find it counterproductive to focus on these formalities when all is needed is a little bit of good faith. But sure, it is way easier to just dispense 50 "Not kotlin" labels per day than answer 1 question and help somebody out
👎🏼 1
👍 4
e
this entire community is about Kotlin. #C0B8MA7FA for general Kotlin topics, #C0BJ0GTE2 for Kotlin news and update, #C0B8L3U69 for Kotlin/JS, not general Javascript issues.
v
Again, what's your point?
e
there are some people here willing to help with Kotlin issues integrating with Android. not general Android SDK issues.
v
Sure, and my question is how to design a class in Kotlin that respects the Android's Context recommendations
🚫 1
c
The point is that for answering your question you need an Android developer and not an Kotlin developer. One that understands what a Context in Android is and what the implications are when you hold a reference to it in your class. Nothing a Kotlin developer can answer. Here we are Kotlin developers and in the links I posted you will find Android developers that can help with your question.
v
Then why is this thread called "Android" ?
c
Because you might find help with integration of Android and Kotlin and not questions about the Android SDK and it’s environment.
v
It is impossible not to touch upon Android SDK when wanting to integrate Kotlin and Android. The 2 cannot be mutually exclusive
Anyway, I don't think this discussion is productive for any of the parties involved. I wish you a good evening and weekend