TheEdge 2010:
The Android platform has matured rapidly during the last two years.
We're going to bring you up to speed in the latest cutting edge Android development techniques including: New UI Patterns, supporting multiple screen resolutions, REST clients, Push applications and optimizing your applications.
2. This presentation is based onTheEdge 2010 Android Application: Download it from the Market Download the source code: http://code.google.com/p/theedge2010/for all the examples in this presentation Before we begin! TheEdge 2010 Android App
15. Implement search in your app Persistent across the application Can be used with the Action Bar Multiple search modes A clearer way to filter results Search Bar UI Design Patterns
16. Declare your application as searchable Declare an activity that handles the search Handle the search itself Implementation UI Design Patterns
21. Contextual actions driven popup menu Natural flow to the screen context Simple and effective Wow effect Quick Actions UI Design Patterns
22. Not in the SDK Custom Views Implementation taken from: Lorenz’s Bloghttp://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/ Implementation UI Design Patterns
26. Vertical scrollable view that allows multiple rows views (List Item) Uses ListAdapter to populate each List Item Recycles Views (So don’t cache them!) Supports different view types A few words about ListView UI Design Patterns
27. ListView should not hold N Views. Use ConvertView in getView method: ListView Recycler UI Design Patterns @Override publicViewgetView(int position, ViewconvertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.speakers_list, parent, false); } //Get your components from the view finalTextViewspeakerName = (TextView) convertView.findViewById(R.id.speaker_name); //Get your item Speakerspeaker = getItem(position); returnconvertView; }
34. Reading is fast Writing is slow Disk space affects performance Make sure you support External Storage (Both in installation and in caches/data) Flash I/O I/O Access
35. Virtual Table that allows Full Text Search Produces results significantly faster than LIKE Comprehensive syntax SQLite FTS I/O Access
36. Creating FTS table Similar to creating a regular table: I/O Access publicclassDatabaseHelperextendsSQLiteOpenHelper { privatestaticfinalStringDATABASE_NAME = "TheEdge"; publicstaticfinalStringSPEAKERS_TABLE = "speakers"; @Language("SQLite") privatestaticfinalStringCREATE_SPEAKERS_TABLE = "CREATE VIRTUAL TABLE " + SPEAKERS_TABLE + " USING fts3 (speaker_name TEXT , bio TEXT, company TEXT, image_uri TEXT)"; publicDatabaseHelper(Contextcontext, String name, SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, version); } @Override publicvoidonCreate(SQLiteDatabasesqLiteDatabase) { Log.i(this.getClass().getSimpleName(), "Creating DB"); sqLiteDatabase.execSQL(CREATE_SPEAKERS_TABLE); }
37. Using: Use the MATCH keyword: I/O Access publicList<Session> searchSessions(String query) { finalList<Session> sessionList = newArrayList<Session>(); finalSQLiteDatabasereadableDatabase = getReadableDatabase(); finalCursorcursor = readableDatabase.rawQuery("select * from " + SESSIONS_TABLE + " where " + SESSIONS_TABLE + " match '" + query + "'", null); if (cursor.moveToFirst()) { do { finalSessionsession = newSession(); session.setTopic(cursor.getString(cursor.getColumnIndex("topic"))); session.setPresenter(cursor.getString(cursor.getColumnIndex("presenter"))); session.setSessionAbstract(cursor.getString(cursor.getColumnIndex("abstract"))); sessionList.add(session); } while (cursor.moveToNext()); } if (!cursor.isClosed()) { cursor.close(); } returnsessionList; }
38. Use a Service Use Apache HTTPClient not URLConnection Don’t do it on the UI thread Parsing can be costly, design your data structure carefully Network I/O Access
39. When using network, remember the following: Availability:Always check connectivity with ConnectivityManager. Performance:Don’t run on the UI Thread, use AsyncTask or Service. Bandwidth:Use as little as you can. Battery drain:Only use the network when you have to. I/O Access
42. Allows you to execute a task without having to manage thread pools. Defined by three generic types: Parameters, Progress and Result. Has a lifecycle: onPreExecute – Called before running the task. doInBackground – Actual work onProgressUpdate – Callback to update the UI on task progress onPostExecute – Called after task has ended, receives the response object Very smart and easy. AsyncTask Optimization
43. In order to implment lazy loading, we’ll need to do the following: Load the ListView an you would normally do. Create a task to fetch the data, use AsyncTask or a Service. Change the data on the UI thread. Use notifyDataSetChanged() to let ListView to update itself. Lazy Loading your ListView Optimization
45. Runs in the background Is not killed when the application ends Running a service is easy Getting callbacks is a bit awkward Declare it in your AndroidManifest.xml Services Optimization
48. ResultReceiver: Implements Parcelable, so can be passed in the Intent object Good for “Here and now” results per intent Getting a Callback from a Service: Optimization
49. ResultReceiver Example Accepts the Activity as the Listener using a custom interface Optimization publicclassNetworkServiceHelperextendsResultReceiver { privatefinalServiceListenerlistener; publicNetworkServiceHelper(ServiceListener listener) { super(new Handler()); this.listener = listener; } @Override protectedvoidonReceiveResult(intresultCode, BundleresultData) { if (listener != null) { listener.onReceiveResult(resultCode, resultData); } } }
Present as a story:Designing smart and cool UIThe work behind to UI – I/OAnd how to make it all work fast
What is an activity: each screen is an activityA screen is defined by a layout, a layout could be an XML or Code. Explain why XML is better than code, and some Layout types.Intent is a way of describing of you want the android OS to do.
When mentioninggoogle IO mention what is it
Your application Home Screen
The first screen the user sees
Explain in short what’s a LinearLayout
Voice search, suggestion, global search
(Don’t believe the emulator!)
Why rawQuery? Query method has too many parameters, they should use a builder…