If I had my druthers, I'd spend all my time developing mobile apps. I've always been fascinated with pocket-sized computers, and have owned many through the years. Unfortunately, for most of my life such devices have been little more than toys, and so I've had to focus my expertise on writing code for "real computers".
This is true even now, during the explosion of smartphone and tablet usage. I'm one of those dinosaurs who knows how to use C, C++, MFC, ATL, CORBA, UNIX, and other ancient magic, so there are sometimes a few months of old-school development between mobile-development gigs. I write iOS stuff for fun, so I keep those skills sharp, but Android is something I touch only when I'm being paid to do so. Thus, I have to find a way to quickly get back up to speed when the Android work does come.
This is my little refresher for when I arrive back in Android-land. It may not help you at all.
WARNING: The below was written back when I wrote apps that targeted Android 2.x. A lot of it is obsolete with the 4.x API. Someday maybe I'll update this.
- Android Development Home
- Android Dev Guide
- Android Design
- Android API Reference
- Google Play (formerly Android Market)
- Downloading Eclipse (get the package for Java developers)
- Note: A new Mac won't have Java the runtime installed. You will be prompted to download and install it when you try to run Eclipse the first time.
- Downloading and Installing the SDK
- Use Ctrl+Space for "Content Assist" (autocomplete)
- Search -> File... is the only decent multi-file search command. And that's where the multi-file Replace button is hidden.
- Code templates, key bindings, and other settings are saved per-workspace. They can be exported and imported into other workspaces.
android update project --path .to prepare a directory for command-line builds. This will create
local.properties. To make a release build, do
ant all clean release.
- App Signing. To share a
debug.keystorebetween developers, create it like this:
keytool -genkey -keypass android -keystore debug.keystore -alias androiddebugkey -storepass android -validity 1000 -dname "CN=Android Debug,O=Android,C=US"
A compatibility library is available to provide newer API features to older API levels.
Styles and Themes
Application-specific styles are defined in XML files in the
res/values folder of the project. Syntax for style definitions is described here: http://developer.android.com/guide/topics/resources/style-resource.html
The standard Android style and theme definitions can be found in the
platforms/android-N/data/res/values folder in the Android SDK (where N is the platform version).
All available style properties are listed here: http://developer.android.com/reference/android/R.attr.html
All available styles are listed here: http://developer.android.com/reference/android/R.style.html
For more on Styles and Themes: http://developer.android.com/guide/topics/ui/themes.html
These tools help generate assets for Android apps:
- Android Asset Studio: http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html
- ActoinBar Style Generator: http://actionbarstylegenerator.com/
- Android Holo Colors: http://android-holo-colors.com
Activities exist in one of three states:
- Resumed (or Running): activity is in foreground and has user focus
- Paused: another activity is in the foreground and has focus, but this activity is still visible
- Stopped: activity is completely obscured, but still maintains state
onCreate()- followed by
onRestart()- followed by
onResume()- followed by
onPause()- followed by
onStop()- followed by
onDestroy()- final call
Activity is killable after
onPause() is "guaranteed" to be called.)
When Activity A starts Activity B:
- If A is no longer visible, its
onSaveInstanceState(Bundle) will be called if an activity may be killed. If called, it will be called before
onStop(), but there are no guarantees about whether it will occur before or after
onPause(). Bundle will be passed to
onRestoreInstanceState(Bundle) if activity is recreated. By default, this mechanism saves/restores states of all views in the hierarchy, as long as each widget has an ID.
Fragments and Loaders
See Fragments and Loaders. Also see http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html.
The compatibility library has support for fragments and loaders. Need to derive class from FragmentActivity and use
For basic implementation of menu triggered by MENU button or action bar, override
To change options menu after creation, override
onPrepareOptionsMenu(). On Android 3.0+, need to call
invalidateOptionsMenu() to force system to call
To create context menu for a view, call
registerForContextMenu(), then implement
More about menus here: http://developer.android.com/guide/topics/ui/menus.html
onCreateDialog(int) and maybe
onPrepareDialog(int, Dialog). Use the
TimePickerDialog classes, or create custom dialog.
showDialog(int) to display the dialog. Call Dialog's
dismiss() or activity's
dismissDialog(int) to close it. Implement
DialogInterface.OnCancelListener for notification.
Consider using new fragments API for dialogs.
ListView and ListActivity
R.layout lists standard list item layouts.
CWAC MergeAdapter makes it easy to bind list items to different kinds of data.
notifyDataSetChanged() method when data changes, to force views and observers to update.
See the Tab Layout tutorial
Note that newer Android apps should use the ActionBar API rather than old-style tabs.