Middle+
What do you consider a flaw in the code that you would immediately want to replace?
sobes.tech AI
Answer from AI
Using findViewById instead of View Binding or Data Binding. findViewById is not type-safe and leads to verbose code.
// Example of using findViewById
val textView: TextView = findViewById(R.id.myTextView)
textView.text = "Hello"
Preferred options:
// Example of using View Binding
// Enabled in build.gradle
// buildFeatures { viewBinding true }
val binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
binding.myTextView.text = "Hello"
// Example of using Data Binding
// Enabled in build.gradle
// buildFeatures { dataBinding true }
// Layout is wrapped in <layout> tag
val binding = DataBindingUtil.setContentView<ActivityMainBinding>(this, R.layout.activity_main)
binding.myTextView.text = "Hello"
Also pay attention to:
- Handling of possible
nullvalues. - Excessively large class or method size (violation of single responsibility principle).
- Use of "magic" strings or numbers instead of constants.
- Code duplication.
- Lack of tests (unit, integration).
- Using outdated APIs (e.g., old versions of Android support libraries).
- Complex code that is hard to understand and maintain without comments or with uninformative comments.
- Improper management of component lifecycle (e.g., memory leaks).
These points often indicate potential issues with the reliability, maintainability, and performance of the application.