Skip to main content
10 votes
Accepted

Recyclerview Adapter for weather app - Makes API calls for each item

First issue You're calling the weather API on every OnBindViewHolder(), which means it will get called for each visible row, and on new rows entering, or re-...
Benito Bertoli's user avatar
6 votes
Accepted

Detecting if image taken by camera is too dark

Intelligibility I can't quite work out what's going on with the main loop. ...
Peter Taylor's user avatar
  • 24.5k
6 votes
Accepted

Code for sorting items in recyclerView

You're right that the duplicate code in the sorters looks bad. To solve this, each sorter should only define the compare function, and all the rest should be done by the enum class. Or not even this. ...
Roland Illig's user avatar
  • 21.9k
5 votes

Detecting if image taken by camera is too dark

Sampling: Don't process ALL pixels The speed mainly depend on the number of operations, in our case, pixels. And a lot of pixels. This means that the larger the image is, the slower your code will ...
Rob Audenaerde's user avatar
5 votes
Accepted

Getting location using LiveData and FusedLocationProviderClient

Let me explain how to work with LiveData - ViewModel and Activity. Right now your ...
Akshay Chordiya's user avatar
5 votes
Accepted

Kotlin text validation

First of all, make attention - your code twice convert and check value. Suppose it's not efficient. Another tiny problem - 1280 and 1500 values is not change prefs.mtuSize… My code: ...
Victor Dmitrienko's user avatar
5 votes

Scanning and indexing files video

Naming The method name load_Directory_Files is a bit odd. To follow general Java naming conventions, it would be something like ...
TomG's user avatar
  • 943
5 votes
Accepted

My Android app is really slow when getting simple data from PHP

When approaching optimization problems (and it kinda is one as you want to make a call faster) its generally best to first make sure that you understand exactly what is happening so when in doubt - ...
Azahe's user avatar
  • 365
5 votes

Calculator App with Kotlin and Android Studio

Crash Dividing by 0 crashes the app ungracefully. Detect this and show an error message. Warnings Check your "Problems" tab in Android studio. It tells you to use ...
ggorlen's user avatar
  • 4,167
5 votes

Android - A way to show/hide loader without writting false/true in every viewmodelScope.launch

If I interpret it correctly, you can basically wrap everything in a single method, and pass it a lambda: ...
Simon Forsberg's user avatar
5 votes
Accepted

Compose Grid With Lists

Looks quite good already, I haven't found any serious issues. The are some minor improvements that I would suggest, though. Small bugs I'm not sure how your data source looks like, but you import <...
tyg's user avatar
  • 498
4 votes
Accepted

Mini game for android

String str = parent.getItemAtPosition(pos).toString(); What does str mean? You proceed to use it to determine the level (i....
Dair's user avatar
  • 6,220
4 votes

Mini space game for Android

You really need to split your code. You have methods that are hundreds of lines long, they should be more like under 10 lines. Then, you can also benefit by trying going more OO. The sequence of <...
antonro's user avatar
  • 302
4 votes
Accepted

About handling data from an API call through RX and Retrofit

Let me start by saying I am by no means an expert in Rx. I have no authoritative references to back up my suggested improvements. They come from the little experience I have, as well as some ...
Tim's user avatar
  • 156
4 votes
Accepted

Android game inspired by Space Invaders and Moon Patrol

Thanks for sharing your code. organize your code use automatic code reordering In your code all the different types of code are mixed. This make it hard to read your code. There is a common order ...
Timothy Truckle's user avatar
4 votes
Accepted

Implementation of an OkHttp singleton for Android

You don't need to create new instance of OkHttpClient. Remove it. You can use Initialization-on-demand holder pattern to create singleton in Java. No need to use <...
thangdc94's user avatar
  • 216
4 votes
Accepted

Android Tetris App Design

Good job separating concerns Your tetris game-board model, piece and UI code is nicely separated in classes, so each one has its own responibility. Well done! Don't use magic values, use Enum ...
Rob Audenaerde's user avatar
4 votes

Kotlin reflection to generate one class from class similar with similar properties

inline functions inline function are great when: You want to surround a lambda with a little code You want to use reified types. They are not great when you have a large function, as every call to ...
tieskedh's user avatar
  • 842
4 votes
Accepted

Google Maps API - reading locations from file and displaying markers on map

Your Marker and ShelterObject instances have the same data inside. (except the additional hardcoded (!) string "Antal platser:", whatever that means) Now you have two islands of data. You collect them ...
Chaarmann's user avatar
  • 121
4 votes
Accepted

Optimize this code of adapter's overriden method getItemCount()

Code Beautification is suggestive. This is how I would write your code. There is also a possible performance optimization by only calling super.getItemCount() once. ...
dfhwze's user avatar
  • 14.2k
4 votes

TCP server in Android to continuously listen to an RFID reader

You should be implementing Runnable, not extending Thread. You are not creating a new generally-useful extension of thread that can be used as an API class by multiple clients. You just want a normal ...
Eric Stein's user avatar
  • 6,726
4 votes
Accepted

Kotlin shared preferences

Welcome to Kotlin! Consider this. ...
Mateusz Herych's user avatar
4 votes

Android Java Splash Screen code

This code looks reasonably clean and seems to accomplish what it's intended to do. Some minor nitpicks can still be improved here and there: You're not consistent in visibility modifier ordering ...
Vogel612's user avatar
  • 25.5k
4 votes
Accepted

Adapter for RecyclerView with supported onClick handling and select color text on last clicked item

I like nitwitting about kotlin, therefor only feedback about the language. single expression functions If your function exists out of one expression, you can write it easier. Instead of having to ...
tieskedh's user avatar
  • 842
4 votes
Accepted

Alternative class to imitate AsyncTask class (deprecated) with Thread and Handler classes

...
Bobby's user avatar
  • 8,166
4 votes
Accepted

Android Tic-Tac-Toe

Reset Calling back into your MainActivity each time you reset the game creates a stack of the activities, so if the user plays several games and tries to quit by pressing the back button, they'll have ...
forsvarir's user avatar
  • 11.8k
4 votes
Accepted

Code for working with a tasks in To-Do Android application

The word "manager" is a class name trap. It's vague and if you don't have a clear idea of exactly what the class is responsible for, you're in danger of violating the single responsibility ...
Tenfour04's user avatar
  • 823
4 votes
Accepted

Getting a single result from multiple LiveData objects

Your way of merging is similar to Rx's combineTransform or Kotlin Flow's combine. The difference is you are forcing the lambda ...
Tenfour04's user avatar
  • 823
4 votes
Accepted

Jetpack Compose: Length-Units Converter

Regarding making this more idiomatic Kotlin code you can take advantage of direct value assignment like so: ...
Ivan Wooll's user avatar
4 votes
Accepted

Logic to check if app was launched for the first time using DataStore

This already looks quite good. Apart from some minor formatting issues I think the following things can be improved: In the MainActivity the property dataStore can ...
tyg's user avatar
  • 498

Only top scored, non community-wiki answers of a minimum length are eligible