Your SlideShare is downloading. ×
Android 101Introduksjon til Android<br />Truls Jørgensenog Are Wold<br />8. september 2010<br />
Truls<br />Are<br />
Bidragsyterefra Android fokusgruppe<br />Hans Petter Eide<br />Knut BjørnarWålberg<br />© 2010 Capgemini. All rights reser...
Agenda<br />© 2010 Capgemini. All rights reserved.<br />
Bakgrunn<br />Android kjøpesoppav Google i 2005 <br />Googlesmotivasjon<br />"Bedretjenesterogbrukeropplevelsepåmobilgirme...
Android!<br />"The first truly open and comprehensive platform for mobile devices, all of the software to run a mobile pho...
© 2010 Capgemini. All rights reserved.<br />
! Android…<br />© 2010 Capgemini. All rights reserved.<br />
Business case - markedsandeler<br />13%<br />13%<br />3%<br />17%<br />© 2010 Capgemini. All rights reserved.<br />
Utviklingsverktøy og dokumentasjon<br />Tilgjengeligeutviklingsplattformer<br />Eclipse, SDK<br />Emulator, ADB, SQLite<br...
..and now for somethingcompletelydifferent!<br />
JZinema<br />BETA!<br />(butreleasingon time)<br />© 2010 Capgemini. All rights reserved.<br />
Byggeklosser  i Android<br />© 2010 Capgemini. All rights reserved.<br />
Byggeklosser  i Android<br />© 2010 Capgemini. All rights reserved.<br />
Intent<br />Intent<br />Activities og intents<br />© 2010 Capgemini. All rights reserved.<br />Intent<br />MovieListActivi...
Skjermbilder<br />© 2010 Capgemini. All rights reserved.<br />
Fra XML til Java<br />© 2010 Capgemini. All rights reserved.<br />// res/layout/movie_list.xml<br /><Button android:id="@+...
MovieList.xml<br /><LinearLayout<br />xmlns:android="http://schemas.android.com/apk/res/android"<br />android:orientation=...
Activity – MovieListActivity.java<br />publicclassMovieListActivityextendsListActivity {<br />	(…)<br />/** Called when th...
Byggeklosser  i Android<br />© 2010 Capgemini. All rights reserved.<br />
Kommunikasjonmellomkomponenter<br /><ul><li>Intents kan:
Starte en Activity – spesifisert, eller ikke
Sende en melding til systemet
Starte eller koble på en Service</li></ul>© 2010 Capgemini. All rights reserved.<br />
Intents mellom activites<br />© 2010 Capgemini. All rights reserved.<br />// MovieListActivity.java<br />final Intent inte...
Intents mellom applikasjoner<br />© 2010 Capgemini. All rights reserved.<br />// MovieDetailsActivity.java<br />final Inte...
Byggeklosser  i Android<br />© 2010 Capgemini. All rights reserved.<br />
Content Provider<br />Wrapper rundt en datakilde<br />For data somønskestilbudttilandreapplikasjoner (egentlig) <br />Stan...
Content Provider: Persistering<br />© 2010 Capgemini. All rights reserved.<br />Content<br />Provider<br />Sqlite DB<br />...
Content Provider: Henting av data<br />© 2010 Capgemini. All rights reserved.<br />Content<br />Provider<br />Sqlite DB<br...
MoviesContentProvider.java<br />publicclassMoviesProviderextendsContentProvider {<br />	publicstaticfinal String AUTHORITY...
MovieListActivity: Cursor og CursorAdapter<br />© 2010 Capgemini. All rights reserved.<br />// Alle filmer i en by<br />Cu...
DEMO:<br />Live debugging<br />Insert "Title, Author, Date"<br />© 2010 Capgemini. All rights reserved.<br />
Byggeklosser  i Android<br />© 2010 Capgemini. All rights reserved.<br />
Konfigurering<br />AndroidManifest.xml<br /><?xml version="1.0" encoding="utf-8"?><br /><manifest xmlns:android="http://sc...
AndroidManifest.xml  - utdrag<br /><?xml version="1.0" encoding="utf-8"?><br /><manifest xmlns:android="http://schemas.and...
Strukturen i en Android-app ligner på en webapp<br />© 2010 Capgemini. All rights reserved.<br />
Testing på Android<br />© 2010 Capgemini. All rights reserved.<br />
DEMO Robotium<br />Insert "Title, Author, Date"<br />© 2010 Capgemini. All rights reserved.<br />
Andre byggeklosser  i Android<br />© 2010 Capgemini. All rights reserved.<br />
En mobil har sine begrensninger<br />Strøm<br />Datatrafikk<br />Begrenset hardware<br />Cursors, liksom?<br />Komplekse l...
Aktivitet starter<br />Forenkletlivssyklus for en Activity<br />onCreate()<br />Bruker går tilbake til aktiviteten<br />on...
Ytelse foran alt<br /><ul><li>Best practices i Java !=  Best practices i Android
Hissig GarbageCollection
Du veit aldri når’em kommer
Nettverk kan være tregt og dyrt
Tenk lokal caching
Trådhåndtering:
Upcoming SlideShare
Loading in...5
×

Android101 : Introduksjon til Android

2,021

Published on

Norwegian slides! Held at JavaZone2010.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,021
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Android101 : Introduksjon til Android"

  1. 1. Android 101Introduksjon til Android<br />Truls Jørgensenog Are Wold<br />8. september 2010<br />
  2. 2. Truls<br />Are<br />
  3. 3. Bidragsyterefra Android fokusgruppe<br />Hans Petter Eide<br />Knut BjørnarWålberg<br />© 2010 Capgemini. All rights reserved.<br />3<br />
  4. 4. Agenda<br />© 2010 Capgemini. All rights reserved.<br />
  5. 5. Bakgrunn<br />Android kjøpesoppav Google i 2005 <br />Googlesmotivasjon<br />"Bedretjenesterogbrukeropplevelsepåmobilgirmermobilnettbrukogmerpengerireklamekassatil Google" (Computerworld UK)<br />"Merinnovasjonpå mobile plattformer", "The world was broken"-  Rich Miner, Google <br />Sidekick<br />T-Mobile G1 / HTC Dream<br />Nexus One<br />© 2010 Capgemini. All rights reserved.<br />
  6. 6. Android!<br />"The first truly open and comprehensive platform for mobile devices, all of the software to run a mobile phone but without the proprietary obstacles that have hindered mobile innovation"<br />- Andy Rubin, Google <br />© 2010 Capgemini. All rights reserved.<br />
  7. 7. © 2010 Capgemini. All rights reserved.<br />
  8. 8. ! Android…<br />© 2010 Capgemini. All rights reserved.<br />
  9. 9. Business case - markedsandeler<br />13%<br />13%<br />3%<br />17%<br />© 2010 Capgemini. All rights reserved.<br />
  10. 10. Utviklingsverktøy og dokumentasjon<br />Tilgjengeligeutviklingsplattformer<br />Eclipse, SDK<br />Emulator, ADB, SQLite<br />Debugging på device<br />Dalvik debug monitor - tilstandpåenheten<br />LogCat<br />Online API reference, Java style<br />http://developer.android.com<br />© 2010 Capgemini. All rights reserved.<br />
  11. 11. ..and now for somethingcompletelydifferent!<br />
  12. 12. JZinema<br />BETA!<br />(butreleasingon time)<br />© 2010 Capgemini. All rights reserved.<br />
  13. 13. Byggeklosser i Android<br />© 2010 Capgemini. All rights reserved.<br />
  14. 14. Byggeklosser i Android<br />© 2010 Capgemini. All rights reserved.<br />
  15. 15. Intent<br />Intent<br />Activities og intents<br />© 2010 Capgemini. All rights reserved.<br />Intent<br />MovieListActivity<br />MovieDetailActivity<br />(eksterne Activities)<br />
  16. 16. Skjermbilder<br />© 2010 Capgemini. All rights reserved.<br />
  17. 17. Fra XML til Java<br />© 2010 Capgemini. All rights reserved.<br />// res/layout/movie_list.xml<br /><Button android:id="@+id/select_city_button“ android:textSize="20dp” /><br />// R.java <br />public static final class id { <br /> (…) <br /> public static final intselect_city_button=0x7f070016; <br />}<br />// MovieListActivity.java <br />mCinemaButton = (Button) findViewById(R.id.select_city_button);<br />
  18. 18. MovieList.xml<br /><LinearLayout<br />xmlns:android="http://schemas.android.com/apk/res/android"<br />android:orientation="vertical"<br />android:layout_width="fill_parent"<br />android:layout_height="fill_parent"<br />android:background="#FFFFFF" <br /> (…) <br /><Button android:id="@+id/movie_list_cinema" <br />android:textSize="20dp"<br />android:background="@drawable/select_city_button"<br />android:text=“@string/select_city_text“ /><br /></LinearLayout><br />Insert "Title, Author, Date"<br />© 2010 Capgemini. All rights reserved.<br />res/values/string.xml:<br />(…)<br /><stringname=”select_city_text">Velgby</string><br />
  19. 19. Activity – MovieListActivity.java<br />publicclassMovieListActivityextendsListActivity {<br /> (…)<br />/** Called when the activity is first created. */<br />@Override<br />publicvoidonCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />setContentView(R.layout.movie_list);<br />mMovieListHeader = (TextView) findViewById(R.id.movie_list_header);<br />currentCity = getSelectedCity();<br />mMovieListHeader.setText(<br />getString(R.string.header_text_now_showing_in) + currentCity);<br />updateMoviesForCity(currentCity);<br /> (…)<br /> }<br />}<br />Insert "Title, Author, Date"<br />© 2010 Capgemini. All rights reserved.<br />
  20. 20. Byggeklosser i Android<br />© 2010 Capgemini. All rights reserved.<br />
  21. 21. Kommunikasjonmellomkomponenter<br /><ul><li>Intents kan:
  22. 22. Starte en Activity – spesifisert, eller ikke
  23. 23. Sende en melding til systemet
  24. 24. Starte eller koble på en Service</li></ul>© 2010 Capgemini. All rights reserved.<br />
  25. 25. Intents mellom activites<br />© 2010 Capgemini. All rights reserved.<br />// MovieListActivity.java<br />final Intent intent = new Intent(this, MovieDetails.class);<br />intent.putExtra(MoviesProvider._ID, id);<br />startActivity(intent);<br />// MovieDetailsActivity.java<br />finalIntentintent = getIntent();<br />long id = intent.getExtras().getLong(MoviesProvider._ID);<br />Insert "Title, Author, Date"<br />
  26. 26. Intents mellom applikasjoner<br />© 2010 Capgemini. All rights reserved.<br />// MovieDetailsActivity.java<br />final Intent intent = new Intent(Intent.ACTION_VIEW);<br />intent.setData(Uri.parse(buyTicketLink));<br />startActivity(intent);<br />// MovieDetailsActivity.java<br />final Intent intent= new Intent(Intent.ACTION_VIEW);<br />intent.setDataAndType( Uri.parse(mMovieDetailsTrailerUrl),"video/*");<br />startActivity(intent);<br />
  27. 27. Byggeklosser i Android<br />© 2010 Capgemini. All rights reserved.<br />
  28. 28. Content Provider<br />Wrapper rundt en datakilde<br />For data somønskestilbudttilandreapplikasjoner (egentlig) <br />Standardiserttilgangtil data vha<br />CONTENT_URI:<br />content://no.jzinema.provider.Movies/movies<br />© 2010 Capgemini. All rights reserved.<br />
  29. 29. Content Provider: Persistering<br />© 2010 Capgemini. All rights reserved.<br />Content<br />Provider<br />Sqlite DB<br />// Lagre en film<br />// CONTENT_URI: content://no.jzinema.provider.Movies/movies<br />Uriuri = mContext.getContentResolver().<br />insert(MoviesProvider.CONTENT_URI, values);<br />
  30. 30. Content Provider: Henting av data<br />© 2010 Capgemini. All rights reserved.<br />Content<br />Provider<br />Sqlite DB<br />// MovieDetailsActiviy.java henter en film: //content://no.jzinema.provider.Movies/movies/5<br />Cursor c = <br />managedQuery(ContentUris.withAppendedId(<br />MoviesProvider.CONTENT_URI, _id), <br /> null, null, null, null);<br />// MovieListActivity.java spør <br />// (blant annet) etter alle filmers id<br />Cursor c = managedQuery(MoviesProvider.CONTENT_URI, COLUMN_ID, null, null, null);<br />
  31. 31. MoviesContentProvider.java<br />publicclassMoviesProviderextendsContentProvider {<br /> publicstaticfinal String AUTHORITY = "no.jzinema.provider.Movies";<br />publicstaticfinal Uri CONTENT_URI = <br />Uri.parse("content://" + AUTHORITY + "/movies");<br />@Override<br />publicbooleanonCreate(…)<br />@Override<br />public Uri insert(…) <br />@Override<br /> public Cursor query(…)<br />@Override<br /> publicint update(…)<br />@Override<br /> publicint delete(…) <br />@Override<br /> public String getType(…)<br />}<br />Insert "Title, Author, Date"<br />© 2010 Capgemini. All rights reserved.<br />
  32. 32. MovieListActivity: Cursor og CursorAdapter<br />© 2010 Capgemini. All rights reserved.<br />// Alle filmer i en by<br />Cursor cursor = getContentResolver().query(<br /> MoviesProvider.CONTENT_URI, COLUMNS,<br />MovieConstants.ATTRIBUTE_ID + " IN (" + movieIds + ")", null, null);<br />startManagingCursor(cursor);<br />// Opprett et cursorAdaptersombenyttercursorentil å populerehverradi listen <br />mAdapter = newMovieListCursorAdapter (this, R.layout.movie_list_row, cursor, COLUMNS, VIEWS_IN_LIST_ROW);<br />// ListActivitytrenger et adapter.<br />this.setListAdapter(mAdapter);<br />Content<br />Provider<br />Sqlite DB<br />
  33. 33. DEMO:<br />Live debugging<br />Insert "Title, Author, Date"<br />© 2010 Capgemini. All rights reserved.<br />
  34. 34. Byggeklosser i Android<br />© 2010 Capgemini. All rights reserved.<br />
  35. 35. Konfigurering<br />AndroidManifest.xml<br /><?xml version="1.0" encoding="utf-8"?><br /><manifest xmlns:android="http://schemas.android.com/apk/res/android"<br />package="no.capgemini.jzinema” android:versionCode="1” android:versionName="1.0"><br /><!-- Permissions --><br /><uses-permission android:name="android.permission.INTERNET" /><br /><application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true"><br /> <!-- Activity for showing a list of movies currently running in the cinemas--><br /> <activity android:name=".MovieList“><br /> <intent-filter><br /><category android:name="android.intent.category.LAUNCHER" /><br /><action android:name="no.capgemini.jzinema.SHOW_MOVIELIST" /><br /></intent-filter><br /></activity><br /><providerandroid:authorities="no.jzinema.provider.Movies“<br />android:name=".provider.MoviesProvider“ /><br /> </application><br /><uses-sdkandroid:minSdkVersion=“4" /><br /></manifest><br />© 2010 Capgemini. All rights reserved.<br />
  36. 36. AndroidManifest.xml - utdrag<br /><?xml version="1.0" encoding="utf-8"?><br /><manifest xmlns:android="http://schemas.android.com/apk/res/android"<br />package="no.capgemini.jzinema” android:versionCode="1” android:versionName="1.0"><br /><!-- Permissions --><br /><uses-permission android:name="android.permission.INTERNET" /><br /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><br /><application android:icon="@drawable/icon" android:label="@string/app_name"><br /><!-- Activity for showing a list of movies currently running in the cinemas. --><br /><activity android:name=".activity.movielist.MovieListActivity"<br />android:label="@string/app_name"<br />android:configChanges="orientation"><br /><intent-filter><br /><action android:name="android.intent.action.MAIN" /><br /><category android:name="android.intent.category.LAUNCHER" /><br /></intent-filter><br /></activity><br /><providerandroid:authorities="no.jzinema.provider.Movies“<br />android:name=".provider.MoviesProvider“ /><br /> </application><br /><uses-sdkandroid:minSdkVersion=“4" /><br /></manifest><br />Insert "Title, Author, Date"<br />© 2010 Capgemini. All rights reserved.<br />
  37. 37. Strukturen i en Android-app ligner på en webapp<br />© 2010 Capgemini. All rights reserved.<br />
  38. 38. Testing på Android<br />© 2010 Capgemini. All rights reserved.<br />
  39. 39. DEMO Robotium<br />Insert "Title, Author, Date"<br />© 2010 Capgemini. All rights reserved.<br />
  40. 40. Andre byggeklosser i Android<br />© 2010 Capgemini. All rights reserved.<br />
  41. 41. En mobil har sine begrensninger<br />Strøm<br />Datatrafikk<br />Begrenset hardware<br />Cursors, liksom?<br />Komplekse livssykluser<br />Multitasking<br />© 2010 Capgemini. All rights reserved.<br />
  42. 42. Aktivitet starter<br />Forenkletlivssyklus for en Activity<br />onCreate()<br />Bruker går tilbake til aktiviteten<br />onStart()<br />onRestart()<br />onResume()<br />Prosess drept<br />Aktivitet kjører<br />Aktivitet havner i forgrunnen<br />Aktivitet havner i bakgrunnen<br />Aktivitet havner i forgrunnen<br />onSaveInstanceState()<br />onPause()<br />Lavt minne<br />Aktiviteten er usynlig<br />onStop()<br />Aktivitet avsluttet<br />Lavt minne,<br />finish()<br />onDestroy()<br />© 2010 Capgemini. All rights reserved.<br />
  43. 43. Ytelse foran alt<br /><ul><li>Best practices i Java != Best practices i Android
  44. 44. Hissig GarbageCollection
  45. 45. Du veit aldri når’em kommer
  46. 46. Nettverk kan være tregt og dyrt
  47. 47. Tenk lokal caching
  48. 48. Trådhåndtering:
  49. 49. AsyncTask
  50. 50. Tråder med en handler</li></ul>© 2010 Capgemini. All rights reserved.<br />
  51. 51. Oppsummering<br />
  52. 52. Fordeler<br />Føles kjent <br />Herlig hardware<br />Debug på device<br />Lett å komme i gang!<br />Godt dokumentert<br />Et moderne OS <br />GC<br />Ryddige APIer<br />Community<br />Enkelt å publisere<br />© 2010 Capgemini. All rights reserved.<br />
  53. 53. Ulemper<br />Mange konfigurasjoner å sikte mot<br />Hardware og OS-versjoner<br />Android Market – ikke Bogstadveien<br />..og ikke betalte applikasjoner i Norge enda<br />TREG emulator<br />© 2010 Capgemini. All rights reserved.<br />
  54. 54. Konklusjon<br />Morsomt<br />Utfordrende begrensninger<br />Vil du utvikle for mobiltelefoner er dette veien å gå!<br />Mer mobilmoro: <br />”Scala på Androider”<br /> kl 14:15, Sal 6<br />Thor Åge Eldby<br />”Fra iPhone-idé til AppStore-publisering”<br />Kl 13:30, sal 7 (lyntale)<br />Markuz Lindgren<br />© 2010 Capgemini. All rights reserved.<br />
  55. 55. © 2010 Capgemini. All rights reserved.<br />SjekkutJZinema!<br />Last ned frahttp://tinyurl.com/jzinema<br />BETA!<br />(butreleasingon time)<br />
  56. 56. Spørsmål?<br />Vi står på Capgeminis stand de neste fire timene<br />Mulighet for å leke med kildekoden på stand eller på http://code.google.com/p/jzinema/<br />Feeds ikke inkludert!<br />© 2010 Capgemini. All rights reserved.<br />
  57. 57. truls.jorgensen@capgemini.com<br />are.wold@capgemini.com<br />
  58. 58. Kilder<br />Pro Android 2<br />GoogleAndroidphoneshipmentsincrease by 886% - http://www.bbc.co.uk/news/technology-10839034 <br />Google'sAndroidstrategyexplained - http://www.computerworlduk.com/in-depth/mobile-wireless/890/analysis-googles-android-mobile-strategy-explained/ <br />Rich Miner sitert på Internetnews: http://www.internetnews.com/mobility/article.php/12220_3780476_2 <br />Bilder<br />Kløverbilde: cygnus921@flickr<br />Android med Androider: iwallenstein<br />Android-bamse: laihiu@flickr<br />Android YAY – maxbraun@flickr<br />Android Mini Collectibles – droidzebra, Inc<br />Googles første prodserver – jurvetson@flickr<br />Zebra stripes: schnappi@flickr<br />Raptor: XKCD # 135<br />Record needle: stevecadman@flickr<br />Satellite dish, ryaninc@flickr<br />EvolutionofAndroid: http://www.intomobile.com/2010/07/13/evolution-of-android-follow-the-gingerbread-roadmap/<br />Andy Rubin ved lanseringen av Android: http://googleblog.blogspot.com/2007/11/wheres-my-gphone.html <br />Ytelse: http://developer.android.com/guide/practices/design/performance.html<br />© 2010 Capgemini. All rights reserved.<br />

×