10 Android Development Mistakes Even Seniors Make (And How to Fix Them)

Artem Asoyan
2 min readFeb 23, 2025

--

Ignoring Memory Leaks 🚨

Mistake: Holding references to Activities/Fragments after they’re destroyed.

// Bad: Static reference to an Activity
public static Activity activity;

// Good: Use WeakReference
private WeakReference<Activity> activityWeakRef;

public MyClass(Activity activity) {
this.activityWeakRef = new WeakReference<>(activity);
}

Blocking the Main Thread ⏳

Mistake: Running network calls on the main thread.

// Bad: Network call on the main thread
String response = networkCall();

// Use Kotlin Coroutines
// Good: Coroutine for background work
viewModelScope.launch {
val response = withContext(Dispatchers.IO) { networkCall() }
updateUI(response)
}

Overlooking Configuration Changes πŸ”„

Mistake: Losing data on screen rotation.

// Bad: Data lost on rotation
private String data;

// Good: Store data in ViewModel
class MyViewModel : ViewModel() {
val data = MutableLiveData<String>()
}

Misusing Fragments 🧩

Mistake: Tightly coupling Fragments and Activities.

// Bad: Directly accessing Activity methods
((MainActivity) getActivity()).doSomething();

// Good: Define an interface
public interface OnFragmentInteraction {
void onAction();
}

// In Fragment
((OnFragmentInteraction) getActivity()).onAction();

Not Testing Thoroughly 🎩

Mistake: Skipping unit tests.

// Bad: No tests for critical logic
fun add(a: Int, b: Int): Int {
return a + b
}

// Good: Unit test for add function
@Test
fun testAdd() {
assertEquals(5, add(2, 3))
}

Overlooking Accessibility β™Ώ

Mistake: Ignoring contentDescription for images.

<!-- Bad: No contentDescription -->
<ImageView android:id="@+id/icon" />

<!-- Good: Add contentDescription -->
<ImageView
android:id="@+id/icon"
android:contentDescription="@string/icon_description" />

Hardcoding Strings and Dimensions πŸ“

Mistake: Hardcoding values in XML or code.

<!-- Bad: Hardcoded string -->
<TextView android:text="Hello World" />

<!-- Good: Reference strings.xml -->
<TextView android:text="@string/hello_world" />

Not Optimizing for Different Screen Sizes πŸ“±

Mistake: Fixed layouts for all screen sizes. (XML)

<!-- Bad: Fixed width and height -->
<Button
android:layout_width="100dp"
android:layout_height="50dp" />

<!-- Good: ConstraintLayout -->
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintWidth_percent="0.5" />

Ignoring ProGuard/R8 Rules πŸ”’

Mistake: Not keeping necessary classes.

*.pro
# Bad: No ProGuard rules
# empty file

# Good: Keep ViewModel classes
-keep class com.example.app.viewmodel.** { *; }

Overloading the App with Libraries πŸ“š

Mistake: Adding unnecessary libraries.

// Bad: Too many libraries
implementation 'library1'
implementation 'library2'
implementation 'library3'

// Good: Minimal dependencies
implementation 'androidx.core:core-ktx:XXX'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:XXX'

Not Following Modern Best Practices πŸš€

Mistake: Using AsyncTask (deprecated).

// Bad: Using AsyncTask
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... voids) {
return null;
}
}.execute();

// Good: Coroutine for background work
viewModelScope.launch {
withContext(Dispatchers.IO) {
// Background work
}
}

Final Thoughts

How many of these mistakes are YOU making? Be honest β€” tag a dev friend who needs this πŸ˜‰

πŸ‘‰ Loved this? Smash the clap button and follow for more Android hacks!

--

--

Artem Asoyan
Artem Asoyan

Written by Artem Asoyan

Head Of Mobile, Android Tech/Team Leader, Career mentoring. 12+ years in software development #MobiusConference2023 #PodlodkaAndroidCrew1 #Leetcode (0.4%)

No responses yet