To gain information about common issues that could be present in our code base, we are going to enable StrictMode
in our app.
StrictMode
helps us detect sensitive activities, such as disk accesses or network calls that we are accidentally performing on the main thread. As you know, performing heavy or long tasks on the main thread is a no-go, because the main thread for Android apps is the UI thread and it should be used only for UI related operations: it's the only way to get smooth animations and a responsive app.
To enable StrictMode
in our app, we just need to add a few lines to MainActivity
, and the onCreate()
methods will look like this:
@Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog...