Skip to main content
10 votes
Accepted

Find index of double number delimiter

The problems with the first approach ...
Tunaki's user avatar
  • 9,273
10 votes
Accepted

SlotMachine game as first Android app

Clear state rather than restart You use this function to restart the game: public void recreateGame(View v) { finish(); startActivity(getIntent()); } ...
janos's user avatar
  • 112k
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

Updating positions of enemies every frame

Some things you could try: Unless the waypoints change position, the objects will continue in the same direction each frame. This means you don't have to recalculate ...
Trent Bartlem's user avatar
6 votes

SlotMachine game as first Android app

// Do the math ... Doesn't provide much explanation. I would instead say: ...
Dair's user avatar
  • 6,008
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.2k
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.4k
5 votes
Accepted

Reading complete contact information in Android

Use AsyncQueryHandler, a helper class to help make handling asynchronous ContentResolver queries easier. It basically wraps the ...
Amandeep Rohila's user avatar
5 votes
Accepted

Setting icons when a tab is selected

You check whether the index of the tab equals the position. If this is the case, use the selected icon, otherwise use the unselected one: ...
mtj's user avatar
  • 4,862
5 votes

Tic Tac Toe in Android

Favor enum values over magic values int c[][]; This holds the board and the numbers represent state. Consider ...
mdfst13's user avatar
  • 21.7k
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
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
  • 265
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
  • 3,987
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
  • 438
4 votes

Android recycler view adapter filter

Consider using iterator instead of for-looping. That will get rid of your index manipulation (decrement if element is removed). ...
Keith Lee's user avatar
4 votes
Accepted

Android recyclerview filter

Your main questions Can I optimize HashMap memory by using ArrayMap? Should I use comma separated positions in ...
janos's user avatar
  • 112k
4 votes

Text messaging app that allows you to interact with AI

In terms of staying organized, one thing you could keep in your mind is something called the Single Responsibility Principle. You may have heard about this before, but if not, it basically says that ...
Langecrew's user avatar
4 votes

SlotMachine game as first Android app

Overall it seems clear enough. I'd like to quibble with a pair of method names, these callback handlers: public void processGame(View v) ... and ...
J_H's user avatar
  • 34.8k
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,008
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
  • 822
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
  • 13.9k
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,626

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