Tips for Developing an Android App: My Lessons Learned

Tips for Developing an Android App: My Lessons Learned

Hey! I’m Ivan and I’ve been an Android application engineer for a long time now. Or then again so it appears. Some time ago (we are discussing 2009), Android was only a baby and I viewed the Little Green Man develop from that point forward. I’m apprehensive some time prior, Android figured out how to grow out of me.

These days, Android isn’t simply on a huge number of various telephones and tablets. It’s on your wrist, in your lounge, in your vehicle, and as soon we begin allotting IP delivers to lifeless things, it will be basically wherever around us. A ton of ground for even an accomplished Android engineer to cover!

Additionally there are more than 1,000,000 applications just on Google Play, not counting Amazon AppStore or markets we are not commonly intrigued by, similar to China.

Things being what they are, in what manner can an autonomous designer make a fruitful application in this gigantic market with huge players? I have no clue, I haven’t made an effective application! In any case, I have made an adorable one, and I’d prefer to impart my story to you.

Lesson 1: Connect The Dots

Success (usually) doesn’t happen overnight and this is not my first app. I have ones ranging from unexpected over-the-weekend development hits like Macedonian Orthodox Calendar, with over 30,000 users in a language that no more than 4 million people can understand, to more successful failures like TweetsPie, an app with heavy media coverage and a terrible user-base of just over 600 active users. A lot of lessons there!

While these apps helped me understand the mind of the “elusive creature called the User” a bit better, the one that inspired me was a two-hour project. Originally developed to make me a millionaire, once 1,428,571 users purchased the app as Google takes 30 cents out of every dollar, The Dollar App was made to test my merchants account.

Little did I know that years later I will receive an email from a happy mom stating that it was the best dollar that she ever spent since her boy was smiling every time my app gave him a hug.

Tips for Developing an Android App: My Lessons Learned
android developement

And that’s how an idea was born! Why not use the fundamental human need for a hug and make it pretty? Make it for a specific audience, interactive, challenging, fun to use, and even more fun to share.

Lesson 2: Understand The Android Market

All the things I mentioned above added up to a live wallpaper app. The basics are not that hard to guess. Android has a bigger market share than iOS, but iOS users purchase more. Messaging apps are wildly popular, but freemium games top the earnings. China, India, Brazil and Russia are emerging markets, but lack spending habits. You can read the App Annie Index for more insights.

So how does a live wallpaper app fit into this? First of all, it eliminates most of the platforms since a live wallpaper is an Android thing. Second, this feature was added in Android 2.1 so it has a large community and quite a few beautiful examples. Most notably Paperland and Roman Nurik’s open source Muzei, probably the best reference point for Android development.

While there are lot of live wallpapers out there, most of them fall under the scenic/weather category, and very few fall under the cuteness overload category. This is something we wanted to change and offer something that gives you a smile each time you unlock your phone, even though you unlocked it for a completely different reason. We gave you a cute little bundle of joy to hug you before you go to bed at night, or when you turn off your alarm in the morning. And even better, make it personal and customizable.

Without further ado, and before we go into technical details, I proudly present you: Ooshies – The Live Wallpaper

Tips for Developing an Android App: My Lessons Learned
android developement

It features:

  • free live wallpaper app that gives you hugs
  • 12 unique ooshies to choose from
  • free, un-lockable, and purchasable content
  • current weather updates
  • social login and data sync
  • seasonal greetings
  • many surprises
  • a ninja cat
  • did we mention hugs?
Tips for Developing an Android App: My Lessons Learned
android developement

Lesson 3: Try To Make It Happen

Ooshies seemed like a pretty straightforward Android app idea. Paint a background, overlay some clouds and stars, put a bear with a balloon on top, and you are good to go. But no, it’s Android! What seems easy is often quite difficult and we tend to repeat the same common mistakes over and over again. Here’s a quick rundown of the challenges I faced:

  1. Hardware acceleration – why draw using the CPU when the GPU is so much better at it? Well, it turns out that drawing bitmaps on a canvas cannot be hardware accelerated. At least not for the time being.
  2. OpenGL – if we want hardware acceleration we need to use OpenGL ES or even better a framework that does most of the work for us.
  3. Bitmap loading – a well known memory consumption issue. We need to allocate 1 byte [0-255] of memory, for each channel in the #ARGB, to display a single pixel. Also the images we use often have higher resolutions than the device’s display. Loading them all will quickly result in OutOfMemroyException.
  4. Home launchers – the live wallpaper will be hosted in the home launcher process, and different launcher tend to give different callbacks to the live wallpaper service (most notably Nova and TouchWiz).
  5. Battery life – if not done right, the live wallpapers and the widgets can drain a lot of battery. With all the buzz about the Lollipop (Android 5.0) terrible battery life the first app to go will be the live wallpaper.

So, overlaying a bitmap, painting it on a canvas, and then switching frames on touch to give a hug, doesn’t seem like a big deal, even when if it is done on the CPU, right? Thats right, it’s not a problem. But, who wants a static live wallpaper? It beats the purpose. The wallpaper should respond to your touches, it should move as you scroll your home screens, it should perform random acts of kindness and make you feel happy.

And there is an Android development trick for that. There is a term called the parallax effect for adding depth in a 2-dimensional space. Imagine yourself driving a car. The house closer to you moves faster than the mountain in the distance. Same effect can be achieved by moving objects in different speed on a canvas. Although, they are all in the same plane, your brain perceives the faster moving objects as closer to you. Much like adding drop shadows, the parallax effect adds a z-axis.

And this is where all hell breaks loose! On most devices moving the Ooshie, the weather overlay, and the background, at different speeds, yields significant frame rate drop. Here’s how a single frame is drawn:

canvas.drawBitmap(background, 0 - offsetX / 4, 0, null);canvas.drawBitmap(weatherOverlay, 0 - offsetX / 2, 0, null);if (!validDoubleTap) {canvas.drawBitmap(ooshieNormal, positionX - offsetX, positionY, null);}else {canvas.drawBitmap(ooshieTapped, positionX - offsetX, positionY, null);}

The offset is a percentage of the distance user has scrolled. It’s a callback that the wallpaper engine provides:

@Overridepublic void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep,int xPixelOffset, int yPixelOffset){super.onOffsetsChanged(xOffset, yOffset, xOffsetStep, yOffsetStep, xPixelOffset, yPixelOffset);// athe current offset should be a fraction of the screen offset to achieve parallaxif (!isPreview()) {float newXOffset = xOffset * 0.15f;wallpaperDrawHelper.setOffsetX(newXOffset);if (isVisible() && hasActiveSurface) {wallpaperDrawHelper.drawFrame(false);}}}

I must note that all of this would be unnecessary if I knew how to work with OpenGL! It’s on my TODO list, since anything more complex than what we have now will require a hardware acceleration. But, for the time being I have to work harder, not smarter (I’m open to suggestions in the comments). So here’s what we did:

Lesson 4: Work With What You Have

As a big supporters of the minSdk=15 initiative, from the start we eliminated all the 2.x devices. The effort for maintaining backward compatibility is greater than the possible revenue from users unableunwilling to upgrade their phones. So, in most cases, we’ll be able to achieve smooth experience with an added option to disable the parallax if desired.

Tips for Developing an Android App: My Lessons Learned
android developement

Another big optimization is how we handle the bitmaps. A very similar parallax effect can be achieved with drawing two bitmaps instead of three:

  1. Ooshie overlay – trimmed and carefully scaled Ooshie bitmap (can be accessorized)
  2. Combined overlay – a combined background and weather bitmap that moves with a fraction of the Ooshie speed

This Android advancement stunt spares memory and rates up the drawing time, for a slight parallax impact debase.

While looking over the home screens, casings will be drawn regularly (in a perfect world in excess of 30 times each second). It’s critical not to draw them when the home screen isn’t noticeable (some lock screens, some application cabinet, opening/exchanging applications, and so forth.) to limit the CPU utilization.

This is all tied intimately with the climate refreshes. At first, there was a repeating task, executing each hour or two, to adjust the climate, yet it was truly overkilled. In the event that the client can’t see the backdrop, the climate data is unessential. So now, climate refreshes happen just when backdrop is noticeable.

long lastUpdate = prefStore.getLong(SharedPrefStore.Pref.WEATHER_TIMESTAMP);if (System.currentTimeMillis() - lastUpdate > Consts.WEATHER_UPDATE_INTERVAL){// update the weather if obsoleteIntent intent = new Intent(getApplicationContext(), WeatherUpdateService.class);startService(intent);}

So, basically, here’s the checklist for a memory optimized smooth software bitmap drawing:

  1. Combine bitmaps once
  2. Draw less bitmaps
  3. Redraw only on demand
  4. Avoid background tasks
  5. Offer users some control over the process

SOURCE:-https://www.toptal.com/android/making-an-android-app-lessons-learned

Leave a Reply

Your email address will not be published. Required fields are marked *