10
votes
Accepted
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());
}
...
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-...
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 ...
6
votes
SlotMachine game as first Android app
// Do the math ...
Doesn't provide much explanation. I would instead say:
...
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.
...
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. ...
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 ...
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:
...
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
...
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 ...
5
votes
Accepted
Getting location using LiveData and FusedLocationProviderClient
Let me explain how to work with LiveData - ViewModel and Activity.
Right now your ...
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:
...
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 - ...
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 ...
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:
...
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 <...
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).
...
4
votes
Accepted
Android recyclerview filter
Your main questions
Can I optimize HashMap memory by using ArrayMap? Should I use comma separated positions in ...
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 ...
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
...
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....
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 <...
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 ...
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 ...
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 <...
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
...
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 ...
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.
...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
android × 779java × 659
performance × 72
kotlin × 67
beginner × 56
sqlite × 37
multithreading × 30
xml × 28
asynchronous × 23
object-oriented × 22
design-patterns × 18
image × 18
error-handling × 17
game × 16
animation × 14
c# × 12
mvvm × 12
rx-java × 12
json × 11
authentication × 11
classes × 11
singleton × 11
layout × 11
datetime × 10
event-handling × 10