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 badge
Add a comment  | 

1 Answer 1

Reset to default 0

If 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