Monday, January 28, 2013

What new Android developers need to know

Android is a new operating system. Apps are written in Java, which is a familiar language to many.  On the other hand, developing for mobile apps is a different beast than with other platforms.  Here are some things I've learned in my years of programming for Android, and I suggest if you are learning Android that you learn about these topics.  I think these make for great interview questions, so it would help to know about these topics if you are going for an Android related interview.


Android Topics

1.       Know what a task is in Android.
a.       How does the task and the navigation stack relate.
b.      What is the difference between default, singleTask, singleTop, etc.?
c.       What happens when you press BACK? 
d.      What happens when you press HOME?
2.       Know what activity lifecycles are. 
a.       When do you use onPause() vs. onDestroy()
b.      What are onConfigurationChange() and retainInstanceState()useful for? 
c.       What happens to static variables when you switch activities?
3.       Know what API levels are. 
a.       Unfortunately, the Android builder does not distinguish API levels. You can build an application with minSdkVersion=3,targetSdkVersion=4 with code which uses methods only available on level 4.  This will build fine, but throw an exception when the class loader attempts to load your class files on an API level 3 phone.
b.      In Eclipse, change the API level to 3 briefly, just to see if the code can compile.
c.       We have to develop with API level 8 in order to use certain features in the manifest, so we have to be very careful about using API methods that are only API levels 1-3. 
d.      You can still use reflection and wrapper classes to prevent class loader from breaking, etc. to use newer classes; examples are available on the Android dev site.
e.      Be wary of the element in the Android manifest.
                                                               i.      An app may be filtered from the Marketplace based on these elements.
                                                             ii.      Bluetooth feature has special rules.
4.       Test your app in all sorts of UI configurations:
a.      Low density, extra large screens, landscape, etc.
b.      A layout may look good on a 320x480 screenshot in a mockup, but did the mockup address how it would look in landscape?
c.       Horizontally laid-out information isn’t good for mobile devices in general.  Keep the layouts flowing vertically.
d.      You get to create all sorts of UI configurations with emulators.
5.       Compress your graphics.  I use an open source program Paint.NET to adjust .PNG images. 
a.       PNG graphics can have unnecessary meta data from graphics programs which take up extra space.
b.      Sometimes encoding in 8-bit vs. 32-bit can save space, but careful that transparency is retained.
c.       If your business customer wants to give you graphics for every type of UI configuration, see if they can accept using a standard image size, and let Android scale the images.  It greatly increases the size of the app.  Android scales the images. 
d.      Use drawables defined in Android XML files when possible instead of bitmaps; they scale well in different sizes and take up less disk space.
6.       Don’t schedule services too often. 
a.       Do you really need to download data from the network every 15 minutes?  This is awful on battery life!
b.      You change the frequency of the service by rescheduling every time the service finishes instead of scheduling a periodic service.

Java in Android

1.       Learn what a strong reference, a weak reference, and a soft reference are. Weak references are especially useful in Android.
a.       Use weak references when dealing with separate threads and timed operations: WeakReference
b.      Both WeakReference and SoftReferences can be useful for some types of caches.
2.       Always use separate threads when doing network operations, disk operations, and other long-running operations.
a.       It turns out that the same code which takes 5 ms can take 5000 ms when Android is out of memory or waiting for other processes to finish file I/O, killing and starting processes, and doing a GC on your app.
                                                               i.      Get used to doing lazy initialization.  It seems unnecessary until you get 500 ANRs on the Marketplace reports.
                                                             ii.      In startup methods, don’t initialize variables.  Wait until an accessor method such as getVariable().
b.      IntentServices, Handlers, Threads.  They are useful in different situations.
c.       IntentServices guarantee a separate thread and that multiple intents handled by the service are synchronized to be processed one after another.
d.      Handlers are useful for transferring messages from the network/etc. threads to the UI thread in an activity.
e.      Threads may be useful in some situations, but remember that a running thread is not a guarantee to keep your process alive; if all activities/services/etc. are closed, then a running thread can (and will) legally be destroyed by the OS.
3.       Be wary of static variables: you don’t have knowledge of their lifecycle, unlike instanced variables accessible through activities and services with onCreate()and onDestroy().
a.       Their value can be reset but
b.      Static variables are notorious for causing memory leaks.
c.      They are useful in some situations still.  For example, preventing code from executing more than once when your process has already started.
4.       Do you know what a memory leak in Java is?  It’s not the same as it is in C.  It refers to keeping strong references to objects which shouldn’t be used anymore (should be GC-able), but programming error has kept them strongly reachable.
a.       In Android especially, you never want to keep references to Activities and Services in variables, especially static variables. 
b.      Sometimes you do need contexts; you can either use Application as a context, or if you have to have the Activity context then 1. Use a weak reference, or 2. Don’t let the object which has a reference to the Activity be referenced by anything else: make sure the Activity completely “owns” the object.
5.       Don’t ever keep static references to Activities, Services, Views, or BroadcastReceivers.
a.       This causes memory leaks!
b.      You can use a global (static) context from the Application
c.       This is useful for getting resources, files, etc. Be careful; you can’t create dialogs from this context, and any activities started with the application context will always create a new task.
d.      If you have to use a static reference, use a WeakReference.


Standards

1.       Build machine is good.
a.       You can create custom Ant scripts.
b.      I use them to copy files based on build properties, and to change variables in the Config.java class.
c.       I also change AndroidManifest.xml using a script based on QA or release builds.
                                                               i.      No worry about developer forgetting to change items.
                                                             ii.      Add/remove debuggable attribute, permissions for logging to SD card, etc.
2.       Always use ProGuard in any app released to the Android Marketplace.
a.       Reduces app size by removing unused variables and methods.
b.      Obfuscates code, which theoretically cannot prevent hackers from snooping but does slow them down.
c.       Allows you to have code  like:
if (Config.LOGGING) print(“The data is: “ + data);The above statement is completely removed when Config.LOGGING isfalse.

3.       Code formatters are useful
a.       Standardization is nice.
b.      Simple whitespace differences can cause merges to break.
c.       If you are using Eclipse, you can check in the project settings into the source repository.
d.      Deciding some standards can be akin to a religious war; after 50 years, lots and lots of smart people have debated this and they haven’t come to the same conclusion on what’s best.  Just go with something.
4.       Hungarian notation is used in Android OS and in some of our apps.
a.       It can be useful, but a developer can easily mess up.  In a strongly-typed symbolic language such as Java, source code formatters do a better job of telling you the data type of a variable.
b.      You don’t have to use the Android OS coding style, but it is an example of a coding style:
                                                               i.      mVariable means instanced field (member variable)
                                                             ii.      sVariable means non-final static field.
                                                            iii.      ALL_CAPS means a constant (final static)
c.       Hungarian Notation was originally meant to describe the type of data as in network response or pixel measurements.  It has been incorrectly used as data type as in “final static” or “DWORD LONG *”.
5.       Use themes and styles in your layouts. 
a.       It makes it easier to make changes.
b.      You’ll probably not use styles the first time you make your layouts. Then when you have to go back and change 25 layout files just to move some pixels to the right, you’ll start using styles.
6.       Put logs everywhere. 
a.       Make a standard for how it’s done. 
b.      No need to remove them or comment them out when using ProGuard if wrapped in a constant boolean; this is a good thing.
c.       I have many ways of dealing with logs:
                                                               i.      Log items to logcat, filterable by one single tag. 
                                                             ii.      Log items to the SD card.  Great because this persists after device resets and lets you observe behavior overnight or over a long time.
                                                            iii.      Added menu item in debug area of app which will automatically e-mail logs to an e-mail address.

Useful reading:

Friday, January 11, 2013

8 Things Remarkably Successful People Do


The most successful people in business work differently. See what they do--and why it works.
runner winning race
Getty
8,840
Share





I'm fortunate to know a number of remarkably successful people. I've described how these people share a set of specific perspectives and beliefs.
They also share a number of habits:
1. They don't create back-up plans.
Back-up plans can help you sleep easier at night. Back-up plans can also create an easy out when times get tough.
You'll work a lot harder and a lot longer if your primary plan simply has to work because there is no other option. Total commitment--without a safety net--will spur you to work harder than you ever imagined possible.
If somehow the worst does happen (and the "worst" is never as bad as you think) trust that you will find a way to rebound. As long as you keep working hard and keep learning from your mistakes, you always will.
2. They do the work...
You can be good with a little effort. You can be really good with a little more effort.
But you can't be great--at anything--unless you put in an incredible amount of focused effort.
Scratch the surface of any person with rare skills and you'll find a person who has put thousands of hours of effort into developing those skills.
There are no shortcuts. There are no overnight successes. Everyone has heard about the 10,000 hours principle but no one follows it... except remarkably successful people.
So start doing the work now. Time is wasting.
3.  ...and they work a lot more.
Forget the Sheryl Sandberg "I leave every day at 5:30" stories. I'm sure she does. But she's not you.
Every extremely successful entrepreneur I know (personally) works more hours than the average person--a lot more. They have long lists of things they want to get done. So they have to put in lots of time.
Better yet, they want to put in lots of time.
If you don't embrace a workload others would consider crazy then your goal doesn't mean that much to you--or it's not particularly difficult to achieve. Either way you won't be remarkably successful.
4. They avoid the crowds.
Conventional wisdom yields conventional results. Joining the crowd--no matter how trendy the crowd or "hot" the opportunity--is a recipe for mediocrity.
Remarkably successful people habitually do what other people won't do. They go where others won't go because there's a lot less competition and a much greater chance for success.
5. They start at the end...
Average success is often based on setting average goals.
Decide what you really want: to be the best, the fastest, the cheapest, the biggest, whatever. Aim for the ultimate. Decide where you want to end up. That is your goal.
Then you can work backwards and lay out every step along the way.
Never start small where goals are concerned. You'll make better decisions--and find it much easier to work a lot harder--when your ultimate goal is ultimate success.
6. ... and they don't stop there.
Achieving a goal--no matter how huge--isn't the finish line for highly successful people. Achieving one huge goal just creates a launching pad for achieving another huge goal.
Maybe you want to create a $100 million business; once you do you can leverage your contacts and influence to create a charitable foundation for a cause you believe in. Then your business and humanitarian success can create a platform for speaking, writing, and thought leadership. Then...
The process of becoming remarkably successful in one field will give you the skills and network to be remarkably successful in many other fields.
Remarkably successful people don't try to win just one race. They expect and plan to win a number of subsequent races.
7. They sell.
I once asked a number of business owners and CEOs to name the one skill they felt contributed the most to their success. Each said the ability to sell.
Keep in mind selling isn't manipulating, pressuring, or cajoling. Selling is explaining the logic and benefits of a decision or position. Selling is convincing other people to work with you. Selling is overcoming objections and roadblocks.
Selling is the foundation of business and personal success: knowing how to negotiate, to deal with "no," to maintain confidence and self-esteem in the face of rejection, to communicate effectively with a wide range of people, to build long-term relationships...
When you truly believe in your idea, or your company, or yourself then you don't need to have a huge ego or a huge personality. You don't need to "sell."
You just need to communicate.
8. They are never too proud.
To admit they made a mistake. To say they are sorry. To have big dreams. To admit they owe their success to others. To poke fun at themselves. To ask for help.
To fail.
And to try again.

http://www.inc.com/jeff-haden/8-habits-of-remarkably-successful-people.html?goback=.gna_156090.gde_156090_member_201613513

Wednesday, January 9, 2013

Get to know Google Developers' products and resources


Takeaway: Ryan Boudreaux gives an overview of the many tools and resources Google Developers has for web developers.
One of the larger ongoing projects succeeding at Google today is theGoogle Developerscommunity, which started out on March 17, 2005 asCode.Google.comwhen it was initially heralded on theGoogle Code Blog. The original Google Code blog started out with a discussion group and included two RSS feeds — one feed for updates and one for featuring a great app, tool, or API using Google code. The Google Code blog has recently evolved into theGoogle Developers Blog, and over the years has come to include much more than just a blog and discussion group. I will give you an overview, highlighting several available tools, products, events, groups, and extensive resources from Google Developers.

Google Developers products

If you are a Mobile Developer, there is Google Mobile Developer, where you can build, promote, earn, measure, and enhance your mobile app. If you are a Games Developer, there is Google GamesDeveloper, where you can build games for web and mobile using Google technologies. If you are a Web Developer, there is GoogleWeb Developer, where you can use the latest HTML5 technologies and Chrome developer tools to build cutting edge web apps. Other tools include Startup,Webmaster, and Monetization apps. Another useful tool in the Google Developers chest includes the Google Web Toolkit (GWT), which I will cover in a bit more detail below. Other technologies and tools available with Google Developers include Google+,Google MapsAndroidApp Engine,AdvertiseGoogle AppsGoogle TV, andCommerce.

Google Web Toolkit (GWT)

In the world of Google Developers are many tools and resources including the Google Web Toolkit(GWT), which is a development toolkit for building and optimizing complex browser-based applications. GWT is used by many internal products at Google, including Google AdWordsand Orkut. The toolkit is open source, completely free, and used by thousands of developers around the world. The GWT includes a suite of features and tools for web development including documentation for current and previous versions, the GWT Designer, which is available for download, and access to numerous GWT resources including articlesbookscase studiescommunitytools and librariespresentationsissue tracking, and a blog. I will present a more in-depth overview of GWT in a future article here on the Web Developer blog.

Google Developers events

Ongoing events continue to populate the Google Developers calendar including local group meet-ups, conventions, system builds, hacks, open source development, apps for business, devcon, and conferences, just to name a few. Several specific events that were on the calendar at the time of this writing include DevFest Campania, which was an open source lab with a talking day and hackathon day. Another event included and Android Build System with Gradle, in Berlin, which included an introduction into the new Android build system based on Gradle, which is targeted to replace the current official build systems (Ant and ADT). And a Google Apps Workshop in Palermo, Italy, which was a free workshop dedicated to the professional management of corporate communication and information security.

Google Developers Showcase

Highlighting cool stuff that developers have built using Google Developer tools, the Google Developers Showcase includes over four hundred showcased applications that utilize many Google APIs such as YouTube Player API, YouTube Data API, YouTube API,  Web Audio API, WebGL, Google Earth API, among others. You can filter searches within the showcase by Product, Region, Theme, and Others. Themes include thirty-one selections including Activism, Business, Experiment, Music, Politics, Travel, and Weather.

Google Developers Live

Google Developers Live (GDL) harnesses the power of live presentations, and includes the Q & A of a developer forum and the global reach of the internet to convey live, streaming content for developers on many of Google’s platforms, including Android, Chrome, Cloud, Maps, YouTube and more. Recent shows have included Google Drive SDKApps Script Office HoursApp Engine Hangout- New experimental dev server for PythonYouTube Developers Live: Geofeedia, andAndroid Developer Lab+.

Google Developers Groups

Google Developer Groups (GDGs) are for developers who are interested in Google’s developer technology, and currently include groups in 95 countries, with 330 active and incubating groups, with 992 events and counting over the past six months. The GDG includes a Starter Guide, Chapter Requirements, Guidelines, Directory, Branding and FAQ. A quick search in the Directoryprovides you with the list of all GDGs sorted by country, and then in alphabetical order by name, where you can find a local chapter to join, and incubating chapters are designated with a yellow location point.
If you are looking to get into development with anything Google related and within the Google Development community, Google Developers is your single source for inspiration. If you are looking for some online training before you delve into the extensive developer tools that I’ve highlighted in this post, then you might want to first visit theGoogle Developers Academy, which provides a set of online classes covering many different Google developer tools and platforms. The course materials also provide developers of all skill levels with curriculum-based learning that goes beyond the traditional technical documentation.