admin管理员组文章数量:1122846
so I'm building this app that is supposed to facilitate master slave relationship over bluetooth by which it gets data from the sensors sends it to master, logs it, shows it...etc I thought it might be a good idea to have a context for each feature (at least the main ones like sensor management and Bluetooth), My idea is that this will facilitate multi-threading and help make this a cleaner program I guess (easier to keep separate as well) i was reading the documentation didn't find much help
val btcontext : Context = public Context()
tried this in mainActivity no luck, um also the contexts are parameters of course to the classes that are going to be used I'm a tad bit chaotic I guess, I hope I explained it well
@SuppressLint("MissingPermission")
class BTController (private val context: Context, private val bluetoothAdapter: BluetoothAdapter?)
: BTMenu {
some context btw im running this for 9+ android
so I'm building this app that is supposed to facilitate master slave relationship over bluetooth by which it gets data from the sensors sends it to master, logs it, shows it...etc I thought it might be a good idea to have a context for each feature (at least the main ones like sensor management and Bluetooth), My idea is that this will facilitate multi-threading and help make this a cleaner program I guess (easier to keep separate as well) i was reading the documentation didn't find much help
val btcontext : Context = public Context()
tried this in mainActivity no luck, um also the contexts are parameters of course to the classes that are going to be used I'm a tad bit chaotic I guess, I hope I explained it well
@SuppressLint("MissingPermission")
class BTController (private val context: Context, private val bluetoothAdapter: BluetoothAdapter?)
: BTMenu {
some context btw im running this for 9+ android
Share Improve this question asked Nov 22, 2024 at 4:37 mustafa qasmiehmustafa qasmieh 51 bronze badge1 Answer
Reset to default 0If you're writing code within your MainActivity
, you can use the term this
, because it serves as your Context
. This technique works in any class that extends an Activity
.
For example:
BTController(
context = this,
bluetoothAdapter = yourAdapter
)
本文标签: androidI want to assign multiple contexts based on seperate features in kotlinStack Overflow
版权声明:本文标题:android - I want to assign multiple contexts based on seperate features in kotlin - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305598a1932646.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论