Android. What'southward not to similar nearly this platform? It's free, it's customizable, it's apace growing and it'southward bachelor not merely on your phone or tablet, but on your smartwatch, TV and auto likewise.

With the latest Lollipop update, Android programming continues to amend. The platform has matured quite a bit since the initial AOSP release, and set the user expectations bar quite loftier. Look how skillful the new Material design design looks!

At that place are thousands of different devices, with different screen sizes, scrap architectures, hardware configurations, and software versions. Unfortunately, partitioning is the price to pay for openness, and there are thousands of ways your app can fail on dissimilar devices, even as an advanced Android programmer.

Regardless of such huge segmentation, the majority of bugs are actually introduced considering of logic errors. These bugs are easily prevented, as long as we get the basics right!

Here's an Android programming tutorial to address the 10 most common mistakes Android developers brand.

Learn Android programming at a more advanced level with this tutorial.

Common Mistake #one: Developing for iOS

To my great pleasure, this Android fault is far less common nowadays (partially because clients are start to realize that the days when Apple was setting all the design standards are long gone). Merely withal, every at present and then, we see an app that is an iOS clone.

Don't get me wrong, I'm non an Android programming evangelist! I respect every platform that moves the mobile world a footstep forward. Just, it's 2014 and users have been using Android for quite a while now, and they've grown accepted to the platform. Pushing iOS blueprint standards to them is a terrible strategy!

Unless there is a super good reason for breaking the guidelines, don't do it. (Google does this all the time, only never past re-create-pasting.)

Here are some of the nearly common examples of this Android mistake:

  1. You should not be making static tabs, and they don't belong on the bottom (I'm pointing at you Instagram).
  2. System notification icons should non have colour.
  3. App icons should not be placed inside a rounded rectangle (unless that's your bodily logo ex. facebook).
  4. Splash screens are redundant beyond the initial setup/introduction. Exercise not use them in other scenarios.
  5. Lists should not have carets.

These are simply a few of the many other small things that can ruin the user experience.

Common Mistake #2: Developing for Your Android Device

Unless you are building a kiosk/promo app for a single tablet, chances are your Android app won't await adept on every device. Hither are a few Android programming tips to remember:

  • Density-contained pixels (dp) are dissimilar than normal pixels (px).
  • Resource are included multiple times to account for different densities and orientations.
  • 9-patch drawables are stretched to fit the screen.

At that place are literally thousands of possible scenarios, simply after a while you lot develop a sense for covering them all with a handful of cases.

Y'all don't own thousands of devices? Not a problem. The Android Emulator is super good in replicating physical devices. Fifty-fifty better, try out Genymotion, it'southward lightning fast and comes with a lot of unlike pop preset devices.

Besides, have you tried rotating your device? All hell tin break loose…

Common Mistake #3: Non Using Intents

Intents are i of Android's key components. It'southward a way of passing information between dissimilar parts of the app or, fifty-fifty ameliorate, different apps on the system.

Let's say you have a gallery app that can share a download link to some images via SMS. Which of the two options seems more logical?

Option 1:

  • Request the SEND_SMS permission.

                                  <uses-permission android:name="android.permission.SEND_SMS" />                          
  • Write your own code for sending SMS using the SmsManager.
  • Explain to your users why your gallery app needs access to services that tin can cost money, and why they have to grant this permission to use your app.

Selection 2:

  • Start an SMS Intent and let an app designed for SMS do the piece of work

                                  Intent sendIntent = new Intent(Intent.ACTION_VIEW);   sendIntent.setData(Uri.parse("sms:" + telephoneNumber));   sendIntent.putExtra("sms_body", 10);   startActivity(sendIntent);                          

In instance that you lot take any doubts, all-time solution is option 2!

This approach can be applied to near anything. Sharing content, taking pictures, recording video, picking contacts, adding events, opening links with native apps, etc.

Unless there is a expert reason to brand a custom implementation (ex., a camera that applies filters), always use Intents for these scenarios. It will salve you a lot of programming fourth dimension, and strip the AndroidManifest.xml of unnecessary permissions.

Mutual Error #4: Not Using Fragments

A while ago in Honeycomb, Android introduced the concept of fragments. Think of them as separate edifice blocks with their ain (rather circuitous) life cycles that exist inside an Action. They help a lot with optimizing for various screens, they are hands managed by their parent activity, tin can be reused, combined and positioned at volition.

Launching a separate activity for each app screen is terribly inefficient, since the system will try to continue them in memory as long every bit it can. Killing one won't gratuitous the resources used by the others.

This Android programming tutorial recommends the proper use of fragments to make your app more efficient.

Unless you want to dig deep into the Android core and read this article, advocating against fragment usage, you should use fragments whenever possible. It basically says that fragments and cursor loaders have good intended purpose, but poor implementation.

Common Fault #5: Blocking the Primary Thread

The main thread has a single purpose: keeping the user interface responsive.

Although the science behind measuring the frame rate our eyes/brain can perceive is complex and influenced by a lot of factors, a full general rule is that anything below 24 fps with delay greater than 100 ms won't exist perceived as smoothen.

This means that the user'southward actions volition have a delayed feedback, and the Android app y'all have programmed volition terminate responding. Stripping the user of his command over the app leads to frustration, frustrated users tend to give very negative feedback.

Even worse, if the chief thread is blocked for a while (5 seconds for Activities, 10 for Broadcast Receivers), ANR will happen.

As you learn Android programming, you will come to know and fear this message.  Follow these Android programming tips to minimize this occurrence.

This was so common in Android 2.x, that on newer versions the system won't let you make network calls in the main thread.

To avoid blocking the primary thread, always apply worker/background threads for: one. network calls 2. bitmap loading iii. image processing 4. database querying five. SD reading / writing

Common Mistake #6: Reinventing the Bicycle

"OK, I won't apply the main thread. I'll write my own code that communicates with my server in a background thread."

No! Delight don't do that! Network calls, image loading, database access, JSON parsing, and social login are the well-nigh common things you do in your app. Non just yours, every app out in that location. There is a ameliorate mode. Remember how Android has matured and grown as a platform? Here's a quick listing of examples:

  1. Use gradle as a build system.
  2. Use Retrofit / Volley for network calls.
  3. Use Picasso for image loading.
  4. Apply Gson / Jackson for JSON parsing.
  5. Apply common implementations for social login.

If you need something implemented, chances are it's already written, tested and used widely. Do some basic research and read some Android programming tutorials earlier writing your own code!

Common Fault #seven: Not Assuming Success

Neat. We accept learned that there is a better mode for handling long running tasks, and we are using well documented libraries for that purpose. But the user will still have to wait. It's inevitable. Packages are not sent, processed and received instantly. In that location is a round trip delay, there are network failures, packages become lost, and dreams get destroyed.

But all this is measurable. Successful network calls are far more than likely than unsuccessful ones. So why expect for server response before handling the successful asking? Information technology'south infinitely meliorate to presume success and handle failure. Then, when a user likes a mail the similar count is immediately increased, and in unlikely upshot that the call failed, the user is notified.

In this modern world immediate feedback is expected. People don't similar to wait. Kids don't want to sit down in a classroom obtaining noesis that has uncertain future payoff. Apps must accommodate to the user's psychology.

Mutual Error #8: Non Understanding Bitmaps

Users beloved content! Particularly when the content is well formatted and looks dainty. Images, for instance, are extremely nice content, mainly due to their property of conveying a thousand words per prototype. They too swallow a lot of memory. A lot of memory!

Before an prototype is displayed on the screen, it has to be loaded into the memory. Since bitmaps are the most common way to practise this, we're going to provide an Android programming guide for the whole procedure:

Let'southward say yous want to display an prototype on your screen that y'all just took with your camera. The total retention needed for this is calculated with the following formula: memory_needed_in_bytes = iv * image_width * image_height;

Why 4? Well, the most common / recommended bitmap configuration is ARGB_8888. That means that for each pixel nosotros draw, we demand to keep eight bits (1 byte) for the alpha, the red, the greed and the blue aqueduct in memory, in guild to properly display it. There are alternatives, similar the RGB_565 configuration that requires half the memory than ARGB_8888, merely loses the transparency and the colour precision (while perchance calculation a light-green tint).

Permit's assume y'all have a brand new device with full HD screen and 12 MP camera. The movie you only took is 4000x3000 pixels big and the total memory needed to display it is: four bytes * 4000 * 3000 = 48 MB

48 megabytes of your RAM just for a unmarried image!? That's a lot!

Now let's accept the screen resolution into consideration. Y'all are trying to show a 4000x3000 paradigm on a screen that has 1920x1080 pixels, in worst case scenario (displaying the image full screen) you shouldn't allocate more than 4 * 1920 * 1080 = eight.3 MB of memory.

Always follow the Android programming tips for displaying bitmaps efficiently:

  1. Measure the view you're showing your images in.
  2. Calibration / crop the large paradigm accordingly.
  3. Testify simply what tin can be displayed.

Mutual Mistake #nine: Using Deep View Hierarchy

Layouts accept an XML presentation in Android. In club to draw content, the XML needs to be parsed, the screen needs to exist measured, and all the elements need to be placed appropriately. It'south a resource- and time-consuming process that needs to be optimized.

This is how the ListView (and more recently the RecyclerView) works.

If a layout has been inflated in one case, the organisation reuses it. Merely however, inflating the layout must happen at some signal.

Allow'south say you lot want to make a 3x3 grid with images. One way of doing this is a vertical LinearLayout containing three LinearLayouts with equal weight, each of them containing 3 ImageViews with equal weight.

Some Android programming beginners don't always make the best use of LinearLayouts.

What exercise we get with this approach? A warning that "nested weights are bad for performance".

At that place is a saying in the Android programming world, that I just made up: "With picayune effort all bureaucracy can be flattened".

In this case RelativeLayout or GridLayout volition efficiently supervene upon the nested LinearLayouts.

Common Mistake #ten: Not Setting the minSdkVersion to fourteen

Well, this is not a fault, but it is bad practice.

Android 2.10 was a huge milestone in developing this platform, but some things should exist left backside. Supporting older devices adds more complexity for code maintenance and limits the development process.

The numbers are clear, the users accept moved on, the developers shouldn't stay behind.

I'grand aware that this doesn't apply for some big markets with old devices (ex. Republic of india), and setting the minSdkVersion to xiv, on the Facebook App, means leaving couple of million users without their favorite social network. Only, if you are starting fresh and trying to create a beautiful experience for your users, exercise consider eliminating the past. Users that don't have the resource, or feel the need to upgrade their device/Os, won't take the incentive to try out a superior version of your Android app and ultimately spend money on it.

Wrap Up

Android is a powerful platform that evolves rapidly. It may non be reasonable to expect users to keep up the pace, simply it's crucial for the Android developers to do so.

Knowing that Android is not merely on our phones or tablets is fifty-fifty more important. It's on our wrists, in our living rooms, in our kitchens, and in our automobiles. Getting the basics right is of utmost importance before nosotros start expanding.

DOWNLOAD HERE

Posted by: schmidhouderat1966.blogspot.com