Tip – Get to Know Collections.sort

Get to know Collections.sort and how to implement custom Comparators.  This might seem like a bore, but if you ever attempt to sort something by yourself or to figure out how to return the indices of something else that has been sorted, then you will thank me.  

For example, imagine that you have an ArrayList that contains lists of an object we will call WorkSet.  Now imagine that each WorkSet item contains a Date that can be grabbed with getDate().  Imagine that you want to sort the ArrayList of lists by the Date of the last element within each of the lists.  Sound like a nightmare?  Not with a custom comparator, it is actually quite simple.

Define a custom Comparator and Override its compare method such that it accepts two instance of List<WorkSet> and returns the following values:

  • Return a negative value if object1 is smaller than object2
  • Return 0 (zero) if object1 is equal to object2.
  • Return a positive value if object1 is larger than object2.

Then call Collections.sort, passing in the ArrayList of List<WorkSet> and the custom comparator.

ArrayList<List<WorkSet>> arrayListArrayListWorksets = new ArrayList<List<WorkSet>>();
...

// Sort the List<WorkSet> by the date of the last value in each list
Comparator<List<WorkSet>> comparator_workset = new Comparator<List<WorkSet>>() {
 @Override
 public int compare(List<WorkSet> set1, List<WorkSet> set2) {
 int last1 = set1.size() - 1;
 int last2 = set2.size() - 1;
 return -1 * set1.get(last1).getDate().compareTo(set2.get(last2).getDate());
 }

};

Collections.sort(arrayListArrayListWorksets, comparator_workset);

Always Include Device Art with Your Screenshots

This is going to be a short post, but it is an easy to miss no-brainer.  Always, always, always include device art with your screenshots before uploading them to your app store page.  If you don’t already know how to do this, you are probably asking yourself, “What the heck is device art?”  “Device Art” is simply a representation of a device, inside of which one can place a screenshot taken from an actual device.  This gives your screenshots the appearance of a high resolution photograph taken of an actual phone or tablet running your app, which would be very difficult to do well in reality.  This is easier to show with images than it is to explain with words, so here you go.  This is a screenshot without device art:

Screenshot_2015-07-11-15-59-39

And this is one with Device Art, in this case Nexus 5:

Screenshot_2015-07-11-15-59-39_framed

This makes your screenshots look 1000% more professional, which I have to imagine could not possibly hurt your conversion rate on the Play Store.  These can easily be created using the device art generator in the Google Developer Console.

Tip – Create a System of SOPs

Create a system of Standard Operating Procedures (SOPs) for yourself for anything that you think you may ever repeated or that you will need to train someone on.  The act of putting it together will slow you down in the short term, but it will speed you up in the long run and drastically increase your understanding of the subject, which cannot be overstressed.  The following are some examples of SOPs that can and should be generated:

  • Gathering User Requirements
  • Gathering User Feedback
  • Launching a new App on The Store
  • Launching an App Update
  • Icon Development and Testing
  • Social Media Strategy
  • Assessing App Analytics
  • Testing New App Features

What to expect when you’re expecting to update your app on the store.

This can be a scary time, especially if you currently have an app on the store getting good reviews.  One mistake in the upload process can send you home crying, or more accurately frantically back to the keyboard, trying to figure out what the problem is.  Now of course you have tested your app on every conceivable device in every possible condition that it might encounter in the wild.  Wait…what?  You haven’t?  Yea, that’s what I thought.  Here are some of the worst things that I can think of happening.  Not that they are the worst things, but they are the worst things that happened to me.  

Early on in my app building career, I didn’t realize that you can and should test both the Debug and Release builds of your application (Android Studio makes this much easier by the way – another great reason to switch if you haven’t already).  I know, a thousand apologies, I didn’t know much when I started out.  Well anyway I tested the Debug version, and everything looked great.  So I uploaded it to Google Play.  Everything looked good.  I uploaded it to Amazon and went to bed.  I got up, made breakfast, took a shower and made the trek to work.  On the shuttle between my parking garage and work, I read an email from Amazon telling me that my app had failed their tests and would not be launched (by the way Amazon actually tests each release before putting it up, something that Google does not do).  The reason:  the app crashes upon loading.  Now you can imagine my panic and how difficult it was to focus on work all day.  At the end of the day I rushed home to figure out what the problem was.  Now, you can’t roll back to a previous version on the store (oh if you could!).  So my only option was to figure out the problem and upload a new version as soon as possible.  Luckily I figured out relatively quickly that the problem was with Proguard and was able to fix it pretty quickly (if you have a Debug version that works flawlessly and a Release build that crashes from the getgo, dollars to donuts that Proguard is your problem).  By the time I released the new build I had had a day of one person updating the app, having it crash and immediately uninstalling it after another.  I don’t blame them, that’s what I would do.  

A simple tweak or upgrade to your UI can also have sneaky little consequences, sometimes only on a particular type of device (this is what really makes Android development a bear).  Once I snazzed up the UI on one of my apps by adding some simple background beyond the default theme.  Turns out that on some devices the code that I used causes the entire background of the view to be black regardless of the color specified.  Luckily, some saint online had figured this out, and I was able to solve the issue quickly.  But not before a 1-star review and who knows how many frustrated would-be users who quietly downloaded the app.  

Bottom Line:  Don’t take launching an update on the store lightly.  Subject every release build that is to be uploaded to the same level of rigorous testing, regardless of how trivial you think the update to be.  

Tip – Working with Human Readable Date and Time in Android

In the course of developing my first 3 apps for Android, I had read over (skimmed of course) the documentation page for SimpleDateFormat probably a half a dozen times before I came across the following gem which is the first thing you need to know because you are more than likely displaying your date to a human:

If you’re formatting for human use, you should use an instance returned from DateFormat as described above. This code:

DateFormat[] formats = new DateFormat[] {

DateFormat.getDateInstance(),

DateFormat.getDateTimeInstance(),

DateFormat.getTimeInstance(),

};

for (DateFormat df : formats) {

System.out.println(df.format(new Date(0)));

}

Produces this output when run on an en_US device in the America/Los_Angeles time zone:

Dec 31, 1969

Dec 31, 1969 4:00:00 PM

4:00:00 PM

So the takeaway message for lazy readers like myself: use “DateFormat.getDateInstance()”, “DateFormat.getDateTimeInstance()” and “DateFormat.getTimeInstance()” to return dates formatted in one of the three respective standards.

Cultivate a Low Information Diet

Tim Ferris lays out the principles of the low information diet in his extraordinary book The 4-Hour Workweek.  It is highly recommended reading so long as it does not distract you from your primary goal of learning the ropes of Android.  Which brings me to the purpose of the low information diet: eliminate distracting activities from your life, as fun and as critical as you now think they may be.  If you are working a full time job, reading the newspaper, following blogs, checking your email 437 times per day, watching the morning and nightly news and listening to talk radio on your way to work, you may be experiencing information overload as well as just distracting yourself from time that you could be spending thinking about you application projects.

I’ve heard that Thomas Edison would completely devote himself to a single project until it was complete, not working on anything else until he found a solution.  Now of course this may not be an option for you if you are not independently wealthy, the proprietor of General Electric or just plain have other life responsibilities.  But still I think this is a valuable mindset when embarking on a project of considerable complexity.

The following are some examples (none of them particularly original) of how you might begin to cultivate a low information diet:

  • Take a break from the news, including on television, in newspapers and on the radio.  Just try it for a limited period.  If anything particularly groundbreaking occurs in the next two weeks, your friends and family will let you know.
  • Take a break from television altogether, or at least commit to a strict time limit every day.  Streaming services are great ways to limit your time as they prevent you from mindlessly checking to see what is on.  Beware of binge watching however.
  • Similarly, limit your time spend on social media.
  • Use Evernote to create a Media Queue for the internet content you consume on a regular basis (even this blog, it’s ok).  Devote some time each week to catch up on the items that will really add to your life and skip the rest.  You will be surprised how much more productive you will be if you incorporate just this one tool!

Tip – Android Asset Studio

Even if you are not planning on developing unique icons inside of your application, you are definitely going to need a unique app launcher icon.  Incorporating a unique icon into your application requires several different version of each piece of art such that the icons show up in the appropriate resolution regardless of the screen size.  I say “several” because I don’t know off the top of my head exactly how many it takes.  And I don’t know that off the top of my head because I use Android Asset Studio to do the legwork for me.  This is a simple, free no-brainer, so there is no point in writing more about it.