Is your Android or iOS app really stable check these parameters

Bal sikandar
MindOrks
Published in
5 min readApr 28, 2018

Developers rely highly on logs to determine any kind of issues in our applications. For example if we get a crash, we get a stack trace and we analyse it to fix the problem. Similarly there are other vital parameters which needs to be tracked to observe any kind of life threatening problems that might be affecting user experience of your app. I am naming a few parameters here and would appreciate any suggestions as well

  1. Crashes
  2. ANRs
  3. API Failures
  4. Images Loading

Crashes

In most cases we decide stability and success of a release solely on crashes and ANR numbers so let’s see how can we do that better. I recommend Crashlytics the most powerful, yet lightest weight crash reporting solution. It’s part of Fabric SDK along with several other tools.

1- Custom logs

Whatever you log with below APIs gets associated with the crashes and is viewable in crashlytics dashboard. It’s really useful to retrace user actions before the crash. Basically you can add below method in your google analytic class, since we fire analytics for almost all user interactions so what better place to track user actions.

Crashlytics.log(msg);Crashlytics.log(int priority, String tag, String msg);

Below image shows custom logs

2- Custom keys

Crashlytics allows you to associate arbitrary key/value pairs with your crash reports, which are viewable right from the Crashlytics dashboard. Also resetting the same key updates the value. So where can we use this? Suppose you have a detail page which displays book information and it crashes your app for a book but you don’t know which one. That’s exactly where we can use custom keys so whenever you open this page first set custom key just like below.

Crashlytics.setString("bookName", "justOpenedBookName");

Remember resetting same key updates the value so you’ll get the name of recently opened book in crashlytics dashboard. Below are other custom key methods.

void setBool(String key, boolean value);

void setDouble(String key, double value);

void setFloat(String key, float value);

void setInt(String key, int value);
void setString(String key, int value);

3- User Information

If you set below information in crashlytics then you can later search for users with given email or identifier in crashlytics dashboard. So if a user gives bad review or writes an angry mail to report a crash or something, you can check his email id in crashlytics and see for any issues.

void Crashlytics.setUserIdentifier(String identifier);void Crashlytics.setUserName(String name);void Crashlytics.setUserEmail(String email);

4- Log Exception

Crashlytics by default captures all un handled exceptions but is that enough we should also track caught exceptions, for that crashlytics provides below API.

Crashlytics.logException(exception);

I personally suggest a variant of above API by passing additional data in exception object. Create exception object as in below code snippet with “class_method_name” and caught exception as parameters. You can also add other page related data if you need. You can later view these in Non-Fatal section of crashlytics dashboard.

//create exception object with your msg data and caught exception
Exception ex = new Exception("class_method_name", exception);
Crashlytics.logException(ex);

There are few other tools as well you might wanna try Firebase Crash Reporting, Appsee, CrashReporter etc.

ANRs

When the UI thread of an Android app is blocked for too long, an “Application Not Responding” (ANR) error is triggered. While development use ANR-Watchdog which detects ANRs in your build and throws exception with relevant data that can be used to fix the problem. In your release version play store console is a good place to view ANR logs of your app.

Check below article to know ANR better.

API Failures

Most of the time people only care about crashes & ANRs data post release to determine whether release was a success, but is that enough? No, because what if some of your APIs are failing due to any reason and user is getting a blank screen or an indeterminate progress bar. That’s why it’s necessary to track these api failures as well. In android we mostly use Retrofit, Fast Android Networking and Volley for our networking needs. Retrofit and Fast Android Networking uses OkHttp client as networking layer and in OkHttp we can create an interceptor to track failed APIs. Check below code snippet to see how.

OkHttpClient.Builder builder = new OkHttpClient.Builder();builder.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
int responseCode = response.code();
if (responseCode >= 300) {
String failureUrl = request.url().toString();
if (!TextUtils.isEmpty(failureUrl)) {
GoogleAnalyticsClient.sendEvent("APIERROR", responseCode + "", failureUrl);
}
}
return response;
}
});

So when you get responseCode > 300 you can log them to your analytics engine whichever you’re using. Here we’re passing “APIERROR” as category, responseCode as action and request url as label in Google analytics engine. To understand what responseCode or statusCode means in API check here.

If you’re using volley then you can do this by overriding deliverError callback of Request class.

@Override
public void deliverError(VolleyError error) {
super.deliverError(error)
if (error != null && error.networkResponse != null) {
int statusCode = error.networkResponse.statusCode;
if (statusCode >= 300 && request != null) {
String failureUrl = request.getOriginUrl();
if (!TextUtils.isEmpty(failureUrl)) {
GoogleAnalyticsClient.sendEvent("APIERROR", statusCode + "", failureUrl);
}
}
}
}

Image Loading Failure

There are a ton of image loading libraries like Picasso, Glide, Fresco, Universal image loader etc. Anyway thing of matter is if due to some error images are not being displayed, users might get discouraged. That’s a bad user experience and if you’re selling a product and you can’t show the item, they wouldn’t buy it. So image failure tracking is a must. All of the above libraries provide image fail & success callbacks and you can trigger event to your analytics with url of image that failed to load. For Ex: In picasso

Picasso.with(getContext())
.load(url)
.into(imageView, new com.squareup.picasso.Callback() {
@Override
public void onSuccess() {

}

@Override
public void onError() {
//add your analytics event here with url
}
});

Apart from above parameters, I think screen rendering time, user engagement should be tracked as well.

Thanks for reading this article. Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me.

Check all the top articles at blog.mindorks.com

Also let’s connect on facebook, twitter, github and linkedin.

--

--

Bal sikandar
MindOrks

Android developer @shuttl Ex @_okcredit. Blogger | Open source contributor https://about.me/balsikandar.