• Save
Android101 : Introduksjon til Android
Upcoming SlideShare
Loading in...5
×
 

Android101 : Introduksjon til Android

on

  • 2,385 views

Norwegian slides! Held at JavaZone2010.

Norwegian slides! Held at JavaZone2010.

Statistics

Views

Total Views
2,385
Views on SlideShare
2,383
Embed Views
2

Actions

Likes
2
Downloads
0
Comments
0

1 Embed 2

http://www.linkedin.com 2

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Android101 : Introduksjon til Android Android101 : Introduksjon til Android Presentation Transcript

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