Wednesday, April 30, 2014

Getting Started with Android Development in 2015 - Windows Version

Getting started as an Android developer can be a bit confusing. Unlike developing for iOS or Windows Phone, Android developers have lots of choices. We can choose our development o/s: Windows, Mac, or Linux. We can choose our IDE: Eclipse, Intellij, or the new Android Studio. We can even choose our device emulators: stick with Android emulator, build one with VirtualBox, or one from Genymotion. Yes, we have a lot of choices and it can be confusing.

So I am going to show you how I set up my PC development environment. I like it because it gives me the best combination of speed and tools to make developing good code easier. Luckily it only consists of three pieces and all of them are free.

Piece Number One: Java SE Development Kit 7u76

There is a bit of confusion in the Android world over which version of Java SE Development Kit we should be using. Java is rarely mentioned on When it is mentioned it is either Java SDK version 6 or 7. Now if you know anything about Java, you know that version 8 is the most recent one, so why are we using a version which is not the latest? Most likely it is related to the ongoing litigation between Google and Oracle combined with the fact that Google has its own version of the Java Virtual Machine. 

There are quite a few devs which say they are using Android with Java version 8. but I see no reason to switch from version 7. I know that it works and that Google says to use it. So until I hear something definitive from Google, I am sticking with it. Luckily it is still available. Don't fret over the security warnings. The warnings are mainly for servers apps built with Java not for Android apps. Use the link below to get the download. You have to be a registered member of Oracle website, but it is free, save a few emails you will get from Oracle.

Once you have installed it. You must add it to your path's variable and you should also create a Java_Home variable. You should do this before you continue, but don't worry it is easy.

Piece Number Two: Android Studio

Android Studio is now the Android's only official IDE. While you can still use Eclipse, support for it is waning so you shouldn't begin learning Android by using it. Besides Android Studio has lots of nice features which make development more pleasant using it. Now there are somethings that don't work with it yet, but the only big thing is the NDK. I don't have any idea when Google is planning to add NDK support to Android Studio. It is super easy to install just go to the link below and follow the instructions.

Piece Number Three: Genymotion Emulator

Genymotion is built on top of Oracle's VirtualBox. Unlike Google's emulators it doesn't try to simulate an ARM processor instead, it uses the full power of your desktop's CPU to run x86 code. The difference is amazing. On a decent PC, Genymotion is fast enough to run games. 

Genymotion is free for personal use, but you do have to register. Go to: 

To register. They will send a link to your email address in order to confirm it. Click the link and you are in. For Windows machines there is a special installation package which combines VirtualBox and Genymotion together. It is the first one listed under Windows. Be sure to choose it. Follow the installation instructions and once complete, you will need to download a few emulated devices. 

So that's it, nice and simple instructions to get you Android development environment up and running on your Windows PC.

Tuesday, April 29, 2014

Understanding Android's WebChromeClient onCreateWindow Method

A complete demo application is on my GitHub account at:

Android's WebViews are pretty easy to use with the notable exception of the WebChromeClient's onCreateWindow. It is called when the webview would like the host application to create a new window. And new is the key. If you don't create a new webview, the call to onCreateWindow will fail, and worse yet, it will fail without exceptions or errors.

I initially had trouble with onCreateWindow. I couldn't seem to get it to work correctly and unfortunately I couldn't find a good working example of its use anywhere on the Internet. So I very carefully read the documentation again and follow the instructions to the letter. My first attempt to use onCreateWindow didn't create a new window, instead I tried to recycle a child webview that was already on the page. It didn't work, it didn't cause an error, and it did create an Intent for the web browser.

In order to get onCreateWindow to work, I created a special layout first. Take a look at main.xml. In it holds both the main webview and a relative layout, mainBrowserLayout, which will hold the child web view once it is created. 

onCreateWindow is triggered whenever the user taps on an <a> tag with the target attribute is set to "_blank". In a browser this would cause the destination link to open in a new window or tab, but since we are in a webview, there is no way to do this without the help of the parent application, hence the called to onCreateWindow and its behavior of launching the browser if the call fails. 

The heart of this application is off course the onCreateWindow method. The first thing it does is remove any current child windows which may still be attached to browserLayout. Then it makes the entire childLayout visible. It is by default set invisible. Next we create a new webview and give it some settings to make it function correctly. I added the new web to browserLayout. Then I do all of the required work to inform the new webview that it will be used to display the new link.

Next we set the webview client. I only implement this method so that I have access to the onPageFinished method. I use this method to read the title of the view, then set that text in mainTitleText TextView. 

To inform the system that our newly create webview will be used for the link's page, we convert the resultMsg.obj into a WebViewTransport, then we call the setWebView with a reference to the new webview. 

The last thing we do isn't necessary but makes things look cooler. We animate the childLayout sliding up from the bottom of the screen. The animation for it and its counterpart sliding down are in the anim folder.

Be sure to check out the complete source code on my GitHub account at the link at the top of the article. 

Thursday, April 24, 2014

Wednesday, April 23, 2014

Samsung Gear App Challenge Coming in May

That's one big check
OK boys and girls, for the past few years Samsung has held developer challenges and hackathons for big prize money. This year they've upped the ante to $1,250,000. That isn't a single prize, but the total prize money which will given away in a series of challenges and hackathons open to developers around the world. If seeing a picture of a developer holding a big check for $200,000 doesn't start your creative juices flowing, I don't know what else
This year's challenge is themed around Samsung Gear. All of the information you need to get started is on Samsung's website. The challenge begins May 8th, so don't wait to the last moment. 

Thursday, April 10, 2014

How to improve your site's performance with the Chrome Dev Tools

Here are the slides from tonight's talk on using the Chrome Dev Tools to improve your site's performance.

Wednesday, April 2, 2014

Beginning Android Class in SoCal

Android is the hottest operating system on the planet, but it can be a pain to get up and going with it. You have to install Java, an IDE, the ADT, a bunch of SDKs, and emulators. Even once you get all that installed, getting an app working and then deploying it to the Google Play Store isn't trivial either. 

So I've team up with the good people of the South Bay Mobile User Group to a two-day Beginning Android development class. Unlike other classes we will start you from the beginning and take you all the way to uploading your app to the store. 

Unlike other classes, I am going to show the tools and techniques used to build production software. So we won't be bothering with a bunch of simple hello world apps. Instead we will build our own app by learning about lists, ajax calls, converting JSON into POJO, unit tests, and more. Once we are done, every student will customize the app and uploaded to the Google Play store. All of the source code is yours to keep.

Yes, we are charging for this class, but if you compare what you get to what it costs, you will find that it is a very good price. The class will be held on Saturday, May 10th and 17th in Torrance, CA which is super easy to get to from Los Angeles, Orange and Riverside counties. Plus traffic won't be an issue since the classes are on Saturday. For more information please check the South Bay Mobile User Group web site.

If you would like to see my teaching style and Android knowledge ahead of the class, please come to a regular SMUG meeting on April 24th. I will be demonstrating Android Wear's preview SDK.