SlideShare ist ein Scribd-Unternehmen logo
1 von 45
はじめてのAndroid開発

     2011/12/08 井谷裕紀
はじめに
 今回、環境構築の話はしません。
 環境構築はここを見れば大丈夫!
http://www.android-
group.jp/index.php?%A5%EF%A1%BC%A5%AD%A5
%F3%A5%B0%A5%B0%A5%EB%A1%BC%A5%D7
%2F%A5%CF%A5%F3%A5%BA%A5%AA%A5%F3%
A5%BB%A5%C3%A5%B7%A5%E7%A5%F3
みなさん
Androidは好きですか?
愚問でしたね。
そんなAndroid大好きなみなさん
Androidと言えば
なにを思い浮かべますか?
愚問でしたね。
機種依存
というわけで
まずは機種依存の話から
そのためには、
Androidのディレクトリ構成を
 理解する必要があります。
0 ディレクトリ構成

              プログラムファイル

               自動生成ファイル

                 Google API




             リソース(xml, 画像, etc.)




             アプリケーションを定義するファイル
1. 機種依存
1-1 よくある機種依存
   解像度、dpi
   カメラ
   メール
   etc.



      今回はまったの
      が、、、、、
1-2-1 端末による解像度・dpiの違い
   Androidは端末によって解像度やdpiが違います
                     ※dpi = dot per inchの略。ピクセル解像度。
       800x480
       960x540
       854x480
       480x320
       etc.




    端末ごとの違いをどう吸収するか。
    もっとも影響を受けるのはレイアウトで
    す。
1-2-2 解像度・dpi別のリソースの管理

   異なる解像度・dpiを吸収するためのもっともシンプ
    ルな方法は、それら毎に画像等のリソースを管理す
    ることです。

   Androidには、複数のリソースを用意することで、そ
    の端末のdpiや解像度に合った適切なリソースを自動
    で読み込む仕組みがあります。
1-2-3 具体的な方法
           res/drawable-ldpi      100〜140dpi
          res/drawable-mdpi       140〜180dpi
           res/drawable-hdpi      190〜250dpi
          res/drawable-nodpi   DPIに依存しない画像


                      さらに応用すると・・・


            res/drawable-320dpi      320dpi
              res/drawble-hdpi-    190〜250dpi
                  800x480         解像度:800x480
              res/drawble-hdpi-    190〜250dpi
                  854x480         解像度:854x480
              res/drawble-hdpi-    190〜250dpi
                  960x540         解像度:960x540
あるAndroiderは言いました。
普通に書けば、
機種依存問題なんてまず起こらない。
    ただしカメラ以外。
Androidには機種依存を吸収する仕組みが
      ちゃんと用意されています。
    その使い方さえ押さえておけば、
機種依存でそこまで深刻な問題は起きません。
ただし
カメラ以外。
2. Android4種の神器
2-1 Android4種の神器
   Activity
       ユーザー・インタフェース(UI)を持つAndroidのア
        プリケーション・プログラム
   Service
       UIを持たず,連続的に情報を提供し続けるプログラ
        ム
   BroadcastReciever
       外部のイベントに対して何らかの反応を返す
   ContentProvider
       データベースなど,特定の条件下においてデータを
        提供する
2-2-1 Activityとは
   主にViewのことを指します。
   Android上で表示されている画面はActivityです。




            Activity
2-2-2 Activityのライフサイクル


Activityには、生成から始
まり、破棄で終わるまでの
ライフサイクルがありま
す。
2-2-3 Activityを作成するには
   Activityクラスを継承し、onCreate()メソッドを
    Overrideします。
public class SampleActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState
    {
      super.onCreate(savedInstanceState);
      // ViewをLayoutを定義しているxmlからセット
      setContentView(R.layout.main);
    }
}
2-3-1 Serviceとは
   主にバックグラウンドで動作し続けるプログラムを
    指します。

   例)
       タイマー機能
       音楽再生
       目覚まし機能
       etc.
2-3-2 Serviceのライフサイクル

Serviceにもライフサイ
クルがあります。
2-3-3 ServiceのBind
   Serviceは通常、一度起動するとActivityからは停止す
    ることしかできません。
   Bindという機能を使うと、ActivityからServiceが提供
    するメソッドを実行することができます。
2-3-4 Serviceを作成するには
       Serviceクラスを継承し、onCreate(), onBind()を
        Overrideします。
    public class SampleService extends Service
    {
             public void onCreate()
             {
                     super.onCreate();
             }

          @Override
          public IBinder onBind(Intent arg0)
          {
            // bind機能は使用しないのでnullを返す
            return null;
          }
    }
2-4-1 BroadcastRecieverとは
   外部からのイベントに応じて処理が発生するプログ
    ラム
       電話が着信したときに何らかの処理を実行する
       端末を再起動した際に何らかの処理を実行する
       etc.
2-4-2 BroadcastRecieverを作成するには
   BroadcastRecieverクラスを継承し、onRecieve()を
    Overrideします。

    public class PgcwSampleReciever extends BroadcastReceiver
    {
             @Override
             public void onReceive(Context context, Intent intent)
             {
             }
    }
2-5 ContentProviderとは
   データを保存する際に使用します。
   端末内のアプリ専用エリアに作成され、アクセス権
    限を定義すれば他のアプリからも使用可能です。
   システムのデータもこれで作成されています。
3. Intent
3-1 Intentとは
   プロセスやスレッドを跨いだ処理を簡単に実現する
    ものです。
       Activityを起動
       Serviceを起動
       etc.
3-2 明示的Intentと暗黙的Intent
   明示的Intent
     直接起動したいClassを指定して呼び出す
    Intent intent = new Intent(context, class);
   暗黙的Intnent
     明示的に起動させるClassを指定せずにIntentのパラメー
      タに起動するClassをある程度推測できるだけの情報を入
      れておくと、該当するClassが呼び出される
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_VIEW);
    intent.setData(Uri.parse(“http://kayac.com”));
    startActivity(intent);
4. Out of memory
4-1 メモリとの戦い
   Android開発はメモリとの戦いと言っても過言ではあ
    りません。
   必ずと言っていいほど、メモリ問題にぶつかりま
    す。

                   そのほとんどの原因が・・・




             画像
4-2 メモリリーク
     Androidはメモリを明示的に開放することはできませ
      ん
      できないといういい方は正しくないかもしれません。
      メソッドは用意されているのですが、あてになりません。

                     どうするか



        来たるべきGCの時に備えて、
とにかく無駄に参照し続けるオブジェクトを持たないことです。
4-3 開発に入る前のポイント
   DEと相談しましょう
       画像を多用しなくてもリッチに見える工夫
       画像のダイエット処理
           画像をダイエットさせるだけで、とっても効果あります


   参考になるURL
       http://www.textdrop.net/soft/android-avoiding-memory-
        leaks/
       http://andbrowser.com/development/knowhow/65/eclipse-
        android-memory-leak-mat/
       http://tomokey.blogspot.com/2011/05/android.html
5. サンプルアプリの紹介
感想
   とってもよくできています。
   とっつきにくさは感じませんでした。
   JAVAを対して知らない僕でもそれなりに開発はでき
    ました!
Android楽しいよ!!
ご静聴ありがとうございました。

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

初めてのAndroid開発