Android UI Design Patterns & Best Practices

18
UI Design Patterns & Best Practices Mike Wolfson July 22, 2010

description

Presentation discussing Android Design Patterns, and Best Practices.

Transcript of Android UI Design Patterns & Best Practices

Page 1: Android UI Design Patterns & Best Practices

UI Design Patterns & Best Practices

Mike Wolfson

July 22, 2010

Page 2: Android UI Design Patterns & Best Practices

Best Practices – Why?

Important to ensure your App follows the established UI guidelines, and performs well

-Otherwise, you will get bad reviews, and not be successful

-Apps that follow common design standards, will “fit” better in the Android ecosystem, and rise to the top

Read the UI design guidelines!http://developer.android.com/guide/practices/ui_guidelines/index.html

Page 3: Android UI Design Patterns & Best Practices

Avoid the Jank

This occurs when the system locks out user input

-Makes the app feel sluggish

-Annoys the user

100 to 200ms is the threshold beyond which users willperceive lag (or lack of "snappiness," if you will)

Android System Monitors:

- No response to an input event - 5 sec

- BroadcastReceiver hasn't finished executing - 10 sec

Resource: http://code.google.com/events/io/2010/sessions/writing-zippy-android-apps.html

Page 4: Android UI Design Patterns & Best Practices

Force Close

If triggered:

Page 5: Android UI Design Patterns & Best Practices

What happens next?

User hits FC button majority of the time.

- Goes away annoyed.

- Leaves Bad Market reviews

- Complex memory structures will

need to be recreated (if user even

decides to return to app)

-Non-synced data is lost

”This App Sux, Force Closes, 1 star”

“Doesn’t work, uninstall”

Page 6: Android UI Design Patterns & Best Practices

Single Threading Model

Android applications normally run entirely on a single (i.e. main) thread.

-This includes the drawing events

-This means, if system is blocked on an operation, the UI thread is blocked (and app is frozen)

Android UI toolkit is not thread-safe and must always be manipulated on the UI thread.

Potentially long running operations (ie. network ordatabase operations, expensive calculations, etc.) should be done in a child thread

Page 7: Android UI Design Patterns & Best Practices

Android Threading Rules

Cardinal rules of Android UI:

1. Do not block the UI thread

2. Make sure the Android UI toolkit is only accessed on the UI thread.

Page 8: Android UI Design Patterns & Best Practices

Avoid FC and Jank – accessing UI thread manually

Android offers several ways to access the UI thread from other threads:   * Activity.runOnUiThread(Runnable)   * View.post(Runnable)   * View.postDelayed(Runnable, long)   * Handler

Problem:

-manually handling threads is error prone, and difficult

Page 9: Android UI Design Patterns & Best Practices

AsyncTask

Goal of AsyncTask is to take care of thread management for you.

private class DownloadImageTask extends AsyncTask {    protected Bitmap doInBackground(String... urls) {        return loadImageFromNetwork(urls[0]);    }

    protected void onPostExecute(Bitmap result) {        mImageView.setImageBitmap(result);

Resources: (read source code in: ShelvesActivity.java and read the docs! http://developer.android.com/reference/android/os/AsyncTask.html )

Page 10: Android UI Design Patterns & Best Practices

IntentService

“Set it and forget it” – places request on Service Queue, which handles action (and “may take as long as necessary”)

public class UpdateService extends IntentService { public class UpdateService extends IntentService {

To call:

Intent selectIntent = new Intent(this, UpdateService.class);        selectIntent.putExtra("userAction",

Page 11: Android UI Design Patterns & Best Practices

Tips to keep your app “snappy”

If your application is doing work in the background, show the user progress is being made

- AsyncTask.getStatus()

For games specifically, do complex computations in child thread

If your app has time-consuming startup, offer a splash screen quickly, then fill in information as it is ready

-inform user about progress

For data sync, database queries, and other long running

processes - use IntentService

Page 12: Android UI Design Patterns & Best Practices

Design patterns

Patterns describe a general solution to a common problem

-Natural by-product of software design lifecycle

Google created these patterns to establish a common UI language

-following them ensures your app “fits” into the Android ecosystem

-apps will feel more integrated, and natural to the user

Android patterns are designed to follow the natural way to

navigate the web

Page 13: Android UI Design Patterns & Best Practices

Contacts Sync/ Quick Contact

Sync your app with Android

contacts

-do this at startup (first time

user runs app)

Make use of “QuickContact“

-deeper integration of app

with phone contacts

Page 14: Android UI Design Patterns & Best Practices

Dashboard

Navigation center for important actions

Highlight only most important/commonly

used capabilities of application

Expose new content to user

Use this as a place to:

-enhance brand

-engage user

-centralize navigation

Make it fun!

Page 15: Android UI Design Patterns & Best Practices

Action Bar

Dedicated real estate at top of screen

to support navigation, and

frequently used operations

Replaces Title Bar

Do use to bring key actions to front

Do use to convey sense of place

Make consistent between activities

-Don’t use for contextual actions

Provide link to home (dashboard)

Page 16: Android UI Design Patterns & Best Practices

Companion Widget

Supports the app by displaying its content on the home screen

Only use to provide extra value -not just a simple link to start your application

Do handoff to app for detailed

views or complicated tasks

Be space efficient

-keep your widget small

Page 17: Android UI Design Patterns & Best Practices

QuickAction

Popup triggered from distinct visual

target

Minimally disruptive to screen context

Straightforward, Fast and FunPresent only most important actions

Use when item doesn’t have meaningful

detail view

Don’t use in contexts that support

multiple selection Resource: http://code.google.com/p/simple-quickactions/

Page 18: Android UI Design Patterns & Best Practices

Conclusion

Avoid the Jank (make sure your application is responsive)

- Don’t block the UI thread

- Offload long running tasks to background threads

-Using AsyncTask or ServiceIntent

-Keep user notified about progress

Ensure your app “fits” in the Android ecosystem by following established UI design patterns

Questions?