SlideShare une entreprise Scribd logo
1  sur  16
Télécharger pour lire hors ligne
ライフサイクル
と非同期処理
2012/03/14(水)@PRO&BSC
         樋口 祐紀
 (higuchi_yuki@probsc.jp)
本日の内容
• Androidアプリは良くおちます
 –回転すると...
 –Homeボタン押してほっておくと...

• バックエンドはクラウド!というアプリは
  たくさんあります
 –ダウンロード処理
 –プログレスダイアログ処理
                        2
エミュレータの使い方
ショットカットで操作してみましょう
    操作        ショートカット
画面の回転 (前へ) Ctrl + F11
画面の回転(次へ) Ctrl + F12
ネットワーク切替     F8
フルスクリーンモード Alt + Enter
トラックボール      F6

トラックボール
             Delete
(キー押下中)
                         4
DDMSの使い方
 Dalvik Debug Monitor
スクリーンショットや着呼が可能
• C:¥android¥android-sdk¥tools¥ddms.bat
  –   キャプチャ
  –   ログ
  –   接続リセット
  –   着呼




                                          6
ライフサイクルとは?
ライフサイクル
      モデル
• Android端末にど
  のような操作を行う
  と、どのような経路
  をたどるか?を常に
  意識しましょう!




                8
package jp.probsc.test;                      public void onPause() {
                                               super.onPause();
import android.app.Activity;
                                               Log.i("trace", “5. onPause");
import android.os.Bundle;
                                             }
import android.util.Log;
                                             public void onStop() {
public class MainActivity
                                               super.onStop();
                 extends Activity {
                                               Log.i("trace", “6. onStop");
  public void onCreate(Bundle state) {       }
    super.onCreate(state);
                                             public void onDestroy() {
    Log.i("trace", “1. onCreate");
                                               super.onDestroy();
  }
                                               Log.i("trace", “7. onDestroy");
  public void onStart() {                    }
    super.onStart();
                                             public void onRestoreInstanceState(Bundle state) {
    Log.i("trace", “2. onStart");
                                               super.onRestoreInstanceState(state);
  }
                                               Log.i("trace", “8. onRestoreInstanceState");
  public void onRestart() {                  }
    super.onRestart();
                                             public void onSaveInstanceState(Bundle state) {
    Log.i("trace", “3. onRestart");
                                               super.onSaveInstanceState(state);
  }
                                               Log.i("trace", “9. onSaveInstanceState");
  public void onResume() {                   }
    super.onResume();
                                             public void onUserLeaveHint() {
    Log.i("trace", “4. onResume");
                                               super.onUserLeaveHint();
  }
                                               Log.i("trace", “10. onUserLeaveHint");
                                             }
                                         }
                                                                                               9
ログ出力と基に表を埋めてみましょう
(1) 起動           (2) Back キー        (3) Home キー
1. onCreate
2. onStart
4. onResume



(4) 回転           (5) 着呼             (6) (3) 後、アイコンタップ




(7) 履歴から他アプリ起動   (8) 小メモリにてHomeキー   (9) (8) 後、アイコンタップ




                                                    10
画面回転に対応するには?
• 縦、横のそれぞれでレイアウトファイルを分ける
                             画面の大きさによって分けるには「layout-hdpi /
                             layout-mdpi / layout-ldpi」などとします。

                             具体的な解像度に対応するには「layout-480x320
                             / layout-854x480」などとします。



• 画面向きを固定する
 <application android:icon="@drawable/icon" android:label="@string/app_name">
   <activity android:name=".MainActivity" android:label="@string/app_name"
             android:screenOrientation="portrait">
 縦向固定

 <application android:icon="@drawable/icon" android:label="@string/app_name">
   <activity android:name=".MainActivity" android:label="@string/app_name"
             android:screenOrientation="landscape">
 横向固定                                                                           11
画面固定して destory 呼ばれなくするには?
... (省略) ...
                                                                    AndroidManifest.xml
<application android:icon="@drawable/icon" android:label="@string/app_name">
  <activity android:name=".MainActivity" android:label="@string/app_name"
    android:screenOrientation="portrait"
    android:configChanges="orientation|keyboardHidden">
... (省略) ...




... (省略) ...
                                                                       MainActivity.java
public class MainActivity extends Activity {
... (省略) ...
    public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);

        Log.i(“trace”, “onConfigurationChanged called");
    }
}
... (省略) ...

                                                                                      12
Web APIの利用
← こんな Toast が表示され
郵便番号検索                                           れば成功です。

API の利用
                                 「zip.php?zn=9800014」の部分を変更し
                                 て結果が変わるか確かめてみましょう。
HttpURLConnection http = null;                              String city =
InputStream in = null;                                       lineStr.substring(
try {                                                          lineStr.indexOf("city=¥"") + 6,
  // HTTP GETにてデータを取得                                          lineStr.indexOf(
  URL url = new URL(                                             "¥" />¥n<value address="));
  "http://zip.cgis.biz/xml/zip.php?zn=9800014");            Toast.makeText(this, city,
  http =                                                     Toast.LENGTH_LONG).show();
    (HttpURLConnection)url.openConnection();            }
  http.setRequestMethod("GET");                     }
  http.connect();                                  }
  in = http.getInputStream();                      catch (Exception ex) {
                                                   }
 // XML の city 属性の値を取得                             finally {
 byte[] line = new byte[1024];                       try {
 while (true) {                                        if (http != null) http.disconnect();
   int size = in.read(line);                           if (in != null) in.close();
   if (size <= 0) break;                             }
                                                     catch (Exception e) {
  String lineStr = new String(line);                 }
  if (lineStr.contains("city=")) {                 }

   ネットにアクセスするため、AndroidManifest.xmlに下記パーミッションを追加しましょう
   <uses-permission android:name="android.permission.INTERNET" />                             14
非同期処理                                                   protected Long doInBackground(
                                                                                         String... params) {
AsyncTask                                                 for (int i = 0; i < 10; i++) {
                                                            if (isCancelled()) break;
... (省略) ...                                                SystemClock.sleep(1000);
                                                            publishProgress((i + 1) * 10);
public void onCreate(Bundle state) {                      }
 super.onCreate(state);                                   return 0L;
    new MyAsyncTask().execute("");                      }
}                                                       protected void onProgressUpdate(
                                                                                       Integer... values) {
public class MyAsyncTask extends                          dialog.setProgress(values[0]);
              AsyncTask<String, Integer, Long> {        }
    ProgressDialog dialog;                              protected void onCancelled() {
    protected void onPreExecute() {                      dialog.dismiss();
      dialog = new ProgressDialog(MainActivity.this);       new AlertDialog.Builder(MainActivity.this)
      dialog.setTitle("Loading data...");                    .setMessage("キャンセル")
      dialog.setProgressStyle(                               .setPositiveButton("OK", null).create().show();
               ProgressDialog.STYLE_HORIZONTAL);        }
      dialog.setOnCancelListener(
                           new OnCancelListener() {     protected void onPostExecute(Long result) {
       public void onCancel(DialogInterface arg) {       dialog.dismiss();
         MyAsyncTask.this.cancel(true);
                                                            new AlertDialog.Builder(MainActivity.this)
       }
                                                              .setMessage("完了!")
      });
                                                              .setPositiveButton("OK", null).create().show();
      dialog.setMax(100);
                                                            }
      dialog.setProgress(0);
                                                        }
      dialog.show();
    }                                                   ... (省略) ...
                                                                                                         15
本日の課題
• じゃんけんゲームの改善
 – 画面回転しても影響がないようにライフサイクルの観
   点から修正しましょう
 – メモリ領域が足りなくなっても破棄されないように修正
   しましょう
• EditTextに郵便番号を入力し、Buttonを押下
  にて「AsyncTask + 郵便番号検索API」を起
  動し、町の名前をTextViewに表示しましょう
                               16

Contenu connexe

Tendances

DOMイベントの基礎から深淵まで
DOMイベントの基礎から深淵までDOMイベントの基礎から深淵まで
DOMイベントの基礎から深淵までMasayuki Nakano
 
Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 Exercise (Japanese)Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 Exercise (Japanese)Jun Furuse
 
Valhalla Update JJUG CCC Spring 2019
Valhalla Update JJUG CCC Spring 2019Valhalla Update JJUG CCC Spring 2019
Valhalla Update JJUG CCC Spring 2019David Buck
 
軽量EvernoteクライアントSmartEverにおけるアプリ高速化の工夫と課題
軽量EvernoteクライアントSmartEverにおけるアプリ高速化の工夫と課題軽量EvernoteクライアントSmartEverにおけるアプリ高速化の工夫と課題
軽量EvernoteクライアントSmartEverにおけるアプリ高速化の工夫と課題Makoto Setoh
 
ActiveResourceが面白すぎる件
ActiveResourceが面白すぎる件ActiveResourceが面白すぎる件
ActiveResourceが面白すぎる件Kazuki MATSUMOTO
 
gumiStudy#5 JavaScript でネイティブiPhone/Androidアプリを作る
gumiStudy#5 JavaScript でネイティブiPhone/Androidアプリを作るgumiStudy#5 JavaScript でネイティブiPhone/Androidアプリを作る
gumiStudy#5 JavaScript でネイティブiPhone/Androidアプリを作るgumilab
 
Composable Callbacks & Listeners
Composable Callbacks & ListenersComposable Callbacks & Listeners
Composable Callbacks & ListenersTaisuke Oe
 
Paging Libraryの利用をやめたいお気持ち表明
Paging Libraryの利用をやめたいお気持ち表明Paging Libraryの利用をやめたいお気持ち表明
Paging Libraryの利用をやめたいお気持ち表明furusin
 
Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Takefumi MIYOSHI
 
PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門kwatch
 
「Html sql」で図書館hpにアクセスしてみよう
「Html sql」で図書館hpにアクセスしてみよう「Html sql」で図書館hpにアクセスしてみよう
「Html sql」で図書館hpにアクセスしてみようKentaro Matsui
 
traitを使って楽したい話
traitを使って楽したい話traitを使って楽したい話
traitを使って楽したい話infinite_loop
 
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」Tsuyoshi Yamamoto
 
LINQソースでGO!
LINQソースでGO!LINQソースでGO!
LINQソースでGO!Kouji Matsui
 
Goの文法の実例と解説
Goの文法の実例と解説Goの文法の実例と解説
Goの文法の実例と解説Ryuji Iwata
 
Javaセキュアコーディングセミナー東京第3回演習の解説
Javaセキュアコーディングセミナー東京第3回演習の解説Javaセキュアコーディングセミナー東京第3回演習の解説
Javaセキュアコーディングセミナー東京第3回演習の解説JPCERT Coordination Center
 
Unit test in android
Unit test in androidUnit test in android
Unit test in androidTatsuya Maki
 

Tendances (20)

DOMイベントの基礎から深淵まで
DOMイベントの基礎から深淵までDOMイベントの基礎から深淵まで
DOMイベントの基礎から深淵まで
 
Clojure
ClojureClojure
Clojure
 
Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 Exercise (Japanese)Tezos Hands on 2019-06-15 Exercise (Japanese)
Tezos Hands on 2019-06-15 Exercise (Japanese)
 
Valhalla Update JJUG CCC Spring 2019
Valhalla Update JJUG CCC Spring 2019Valhalla Update JJUG CCC Spring 2019
Valhalla Update JJUG CCC Spring 2019
 
Synthesijer hls 20150116
Synthesijer hls 20150116Synthesijer hls 20150116
Synthesijer hls 20150116
 
軽量EvernoteクライアントSmartEverにおけるアプリ高速化の工夫と課題
軽量EvernoteクライアントSmartEverにおけるアプリ高速化の工夫と課題軽量EvernoteクライアントSmartEverにおけるアプリ高速化の工夫と課題
軽量EvernoteクライアントSmartEverにおけるアプリ高速化の工夫と課題
 
ActiveResourceが面白すぎる件
ActiveResourceが面白すぎる件ActiveResourceが面白すぎる件
ActiveResourceが面白すぎる件
 
gumiStudy#5 JavaScript でネイティブiPhone/Androidアプリを作る
gumiStudy#5 JavaScript でネイティブiPhone/Androidアプリを作るgumiStudy#5 JavaScript でネイティブiPhone/Androidアプリを作る
gumiStudy#5 JavaScript でネイティブiPhone/Androidアプリを作る
 
Composable Callbacks & Listeners
Composable Callbacks & ListenersComposable Callbacks & Listeners
Composable Callbacks & Listeners
 
Paging Libraryの利用をやめたいお気持ち表明
Paging Libraryの利用をやめたいお気持ち表明Paging Libraryの利用をやめたいお気持ち表明
Paging Libraryの利用をやめたいお気持ち表明
 
About Jobs
About JobsAbout Jobs
About Jobs
 
Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512
 
PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門PHP5.5新機能「ジェネレータ」初心者入門
PHP5.5新機能「ジェネレータ」初心者入門
 
「Html sql」で図書館hpにアクセスしてみよう
「Html sql」で図書館hpにアクセスしてみよう「Html sql」で図書館hpにアクセスしてみよう
「Html sql」で図書館hpにアクセスしてみよう
 
traitを使って楽したい話
traitを使って楽したい話traitを使って楽したい話
traitを使って楽したい話
 
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
「Grails-1.1を斬る!〜Grails-1.1からのチーム開発〜」
 
LINQソースでGO!
LINQソースでGO!LINQソースでGO!
LINQソースでGO!
 
Goの文法の実例と解説
Goの文法の実例と解説Goの文法の実例と解説
Goの文法の実例と解説
 
Javaセキュアコーディングセミナー東京第3回演習の解説
Javaセキュアコーディングセミナー東京第3回演習の解説Javaセキュアコーディングセミナー東京第3回演習の解説
Javaセキュアコーディングセミナー東京第3回演習の解説
 
Unit test in android
Unit test in androidUnit test in android
Unit test in android
 

En vedette

Android Lecture #02 @PRO&BSC Inc.
Android Lecture #02 @PRO&BSC Inc.Android Lecture #02 @PRO&BSC Inc.
Android Lecture #02 @PRO&BSC Inc.Yuki Higuchi
 
Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Yuki Higuchi
 
Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.Yuki Higuchi
 
AOZORAYOMITE and Intent
AOZORAYOMITE and IntentAOZORAYOMITE and Intent
AOZORAYOMITE and IntentYuki Higuchi
 
AozoraYomite @InfoTalk 2012/12/21
AozoraYomite @InfoTalk 2012/12/21AozoraYomite @InfoTalk 2012/12/21
AozoraYomite @InfoTalk 2012/12/21Yuki Higuchi
 
Programmer @jc-21 2014/03/29
Programmer @jc-21 2014/03/29Programmer @jc-21 2014/03/29
Programmer @jc-21 2014/03/29Yuki Higuchi
 
カジュアルにMongo dbのbackup機能説明
カジュアルにMongo dbのbackup機能説明カジュアルにMongo dbのbackup機能説明
カジュアルにMongo dbのbackup機能説明Masakazu Matsushita
 
月間10億pvを支えるmongo db
月間10億pvを支えるmongo db月間10億pvを支えるmongo db
月間10億pvを支えるmongo dbYuji Isobe
 

En vedette (9)

Android Lecture #02 @PRO&BSC Inc.
Android Lecture #02 @PRO&BSC Inc.Android Lecture #02 @PRO&BSC Inc.
Android Lecture #02 @PRO&BSC Inc.
 
Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.Android Lecture #04 @PRO&BSC Inc.
Android Lecture #04 @PRO&BSC Inc.
 
Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.Android Lecture #01 @PRO&BSC Inc.
Android Lecture #01 @PRO&BSC Inc.
 
AOZORAYOMITE and Intent
AOZORAYOMITE and IntentAOZORAYOMITE and Intent
AOZORAYOMITE and Intent
 
AozoraYomite @InfoTalk 2012/12/21
AozoraYomite @InfoTalk 2012/12/21AozoraYomite @InfoTalk 2012/12/21
AozoraYomite @InfoTalk 2012/12/21
 
Programmer @jc-21 2014/03/29
Programmer @jc-21 2014/03/29Programmer @jc-21 2014/03/29
Programmer @jc-21 2014/03/29
 
カジュアルにMongo dbのbackup機能説明
カジュアルにMongo dbのbackup機能説明カジュアルにMongo dbのbackup機能説明
カジュアルにMongo dbのbackup機能説明
 
月間10億pvを支えるmongo db
月間10億pvを支えるmongo db月間10億pvを支えるmongo db
月間10億pvを支えるmongo db
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Similaire à Android Lecture #03 @PRO&BSC Inc.

Tokyo GTUG Bootcamp2010
Tokyo GTUG Bootcamp2010Tokyo GTUG Bootcamp2010
Tokyo GTUG Bootcamp2010Takashi EGAWA
 
Leap Motion - 1st Review
Leap Motion - 1st ReviewLeap Motion - 1st Review
Leap Motion - 1st ReviewTsukasa Sugiura
 
Jetpack Composeのパフォーマンスの基本
Jetpack Composeのパフォーマンスの基本Jetpack Composeのパフォーマンスの基本
Jetpack Composeのパフォーマンスの基本Damper Matsu
 
「Windows 8 ストア アプリ開発 tips」 hokuriku.net vol.11 (2013年1月26日)
「Windows 8 ストア アプリ開発 tips」  hokuriku.net vol.11 (2013年1月26日)「Windows 8 ストア アプリ開発 tips」  hokuriku.net vol.11 (2013年1月26日)
「Windows 8 ストア アプリ開発 tips」 hokuriku.net vol.11 (2013年1月26日)Fujio Kojima
 
Javaセキュアコーディングセミナー東京第3回講義
Javaセキュアコーディングセミナー東京第3回講義Javaセキュアコーディングセミナー東京第3回講義
Javaセキュアコーディングセミナー東京第3回講義JPCERT Coordination Center
 
Twitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hackTwitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hackkimukou_26 Kimukou
 
ソーシャルアプリ勉強会(第一回資料)配布用
ソーシャルアプリ勉強会(第一回資料)配布用ソーシャルアプリ勉強会(第一回資料)配布用
ソーシャルアプリ勉強会(第一回資料)配布用Yatabe Terumasa
 
Html5 Web Applications
Html5  Web ApplicationsHtml5  Web Applications
Html5 Web Applicationstotty jp
 
クラウド時代の並列分散処理技術
クラウド時代の並列分散処理技術クラウド時代の並列分散処理技術
クラウド時代の並列分散処理技術Koichi Fujikawa
 
第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」yoshiaki iwanaga
 
[東京] JapanSharePointGroup 勉強会 #2
[東京] JapanSharePointGroup 勉強会 #2[東京] JapanSharePointGroup 勉強会 #2
[東京] JapanSharePointGroup 勉強会 #2Atsuo Yamasaki
 
初めての Data api cms どうでしょう - 大阪夏の陣
初めての Data api   cms どうでしょう - 大阪夏の陣初めての Data api   cms どうでしょう - 大阪夏の陣
初めての Data api cms どうでしょう - 大阪夏の陣Yuji Takayama
 
Data apiで実現 進化するwebの世界
Data apiで実現 進化するwebの世界Data apiで実現 進化するwebの世界
Data apiで実現 進化するwebの世界Yuji Takayama
 
Java初心者勉強会(2015/08/07)資料
Java初心者勉強会(2015/08/07)資料Java初心者勉強会(2015/08/07)資料
Java初心者勉強会(2015/08/07)資料Toshio Ehara
 
デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくる
デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくるデジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくる
デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくるAtsushi Tadokoro
 
Continuation with Boost.Context
Continuation with Boost.ContextContinuation with Boost.Context
Continuation with Boost.ContextAkira Takahashi
 
20130924 Picomon CRH勉強会
20130924 Picomon CRH勉強会20130924 Picomon CRH勉強会
20130924 Picomon CRH勉強会Yukihiro Kitazawa
 
Titanium Mobile
Titanium MobileTitanium Mobile
Titanium MobileNaoya Ito
 
Data api workshop at Co-Edo
Data api workshop at Co-EdoData api workshop at Co-Edo
Data api workshop at Co-EdoYuji Takayama
 

Similaire à Android Lecture #03 @PRO&BSC Inc. (20)

Tokyo GTUG Bootcamp2010
Tokyo GTUG Bootcamp2010Tokyo GTUG Bootcamp2010
Tokyo GTUG Bootcamp2010
 
Leap Motion - 1st Review
Leap Motion - 1st ReviewLeap Motion - 1st Review
Leap Motion - 1st Review
 
Jetpack Composeのパフォーマンスの基本
Jetpack Composeのパフォーマンスの基本Jetpack Composeのパフォーマンスの基本
Jetpack Composeのパフォーマンスの基本
 
「Windows 8 ストア アプリ開発 tips」 hokuriku.net vol.11 (2013年1月26日)
「Windows 8 ストア アプリ開発 tips」  hokuriku.net vol.11 (2013年1月26日)「Windows 8 ストア アプリ開発 tips」  hokuriku.net vol.11 (2013年1月26日)
「Windows 8 ストア アプリ開発 tips」 hokuriku.net vol.11 (2013年1月26日)
 
Javaセキュアコーディングセミナー東京第3回講義
Javaセキュアコーディングセミナー東京第3回講義Javaセキュアコーディングセミナー東京第3回講義
Javaセキュアコーディングセミナー東京第3回講義
 
Twitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hackTwitter sphere of #twitter4j #twtr_hack
Twitter sphere of #twitter4j #twtr_hack
 
ソーシャルアプリ勉強会(第一回資料)配布用
ソーシャルアプリ勉強会(第一回資料)配布用ソーシャルアプリ勉強会(第一回資料)配布用
ソーシャルアプリ勉強会(第一回資料)配布用
 
Html5 Web Applications
Html5  Web ApplicationsHtml5  Web Applications
Html5 Web Applications
 
クラウド時代の並列分散処理技術
クラウド時代の並列分散処理技術クラウド時代の並列分散処理技術
クラウド時代の並列分散処理技術
 
第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」第三回ありえる社内勉強会 「いわががのLombok」
第三回ありえる社内勉強会 「いわががのLombok」
 
[東京] JapanSharePointGroup 勉強会 #2
[東京] JapanSharePointGroup 勉強会 #2[東京] JapanSharePointGroup 勉強会 #2
[東京] JapanSharePointGroup 勉強会 #2
 
初めての Data api cms どうでしょう - 大阪夏の陣
初めての Data api   cms どうでしょう - 大阪夏の陣初めての Data api   cms どうでしょう - 大阪夏の陣
初めての Data api cms どうでしょう - 大阪夏の陣
 
Data apiで実現 進化するwebの世界
Data apiで実現 進化するwebの世界Data apiで実現 進化するwebの世界
Data apiで実現 進化するwebの世界
 
Java初心者勉強会(2015/08/07)資料
Java初心者勉強会(2015/08/07)資料Java初心者勉強会(2015/08/07)資料
Java初心者勉強会(2015/08/07)資料
 
デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくる
デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくるデジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくる
デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくる
 
Continuation with Boost.Context
Continuation with Boost.ContextContinuation with Boost.Context
Continuation with Boost.Context
 
20130924 Picomon CRH勉強会
20130924 Picomon CRH勉強会20130924 Picomon CRH勉強会
20130924 Picomon CRH勉強会
 
Rakuten tech conf
Rakuten tech confRakuten tech conf
Rakuten tech conf
 
Titanium Mobile
Titanium MobileTitanium Mobile
Titanium Mobile
 
Data api workshop at Co-Edo
Data api workshop at Co-EdoData api workshop at Co-Edo
Data api workshop at Co-Edo
 

Dernier

Establishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfEstablishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfoganekyokoi
 
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイントshu1108hina1020
 
International Politics I - Lecture 1
International Politics I - Lecture 1International Politics I - Lecture 1
International Politics I - Lecture 1Toru Oga
 
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...yutakashikano1984
 
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrKARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrRodolfFernandez1
 
Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...oganekyokoi
 
The first time I used CANVA to create a slide document.
The first time I used CANVA to create a slide document.The first time I used CANVA to create a slide document.
The first time I used CANVA to create a slide document.oganekyokoi
 
Divorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfDivorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfoganekyokoi
 
What I did before opening my business..pdf
What I did before opening my business..pdfWhat I did before opening my business..pdf
What I did before opening my business..pdfoganekyokoi
 

Dernier (9)

Establishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdfEstablishment and operation of medical corporations.pdf
Establishment and operation of medical corporations.pdf
 
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
3年前期 交通基盤工学 第一回 ガイダンス 交通基盤工学の概要  パワーポイント
 
International Politics I - Lecture 1
International Politics I - Lecture 1International Politics I - Lecture 1
International Politics I - Lecture 1
 
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
レポートの書き方講座 [大学生初年次向けに対する講義資料] Lecture on how to write a report [lecture mater...
 
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhrKARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
KARAPATANG PANTAO.pptxhrhrhrhrhrhrhrhrhr
 
Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...Registration of travel agents - 'Explanation of the registration system under...
Registration of travel agents - 'Explanation of the registration system under...
 
The first time I used CANVA to create a slide document.
The first time I used CANVA to create a slide document.The first time I used CANVA to create a slide document.
The first time I used CANVA to create a slide document.
 
Divorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdfDivorce agreements in administrative work.pdf
Divorce agreements in administrative work.pdf
 
What I did before opening my business..pdf
What I did before opening my business..pdfWhat I did before opening my business..pdf
What I did before opening my business..pdf
 

Android Lecture #03 @PRO&BSC Inc.

  • 2. 本日の内容 • Androidアプリは良くおちます –回転すると... –Homeボタン押してほっておくと... • バックエンドはクラウド!というアプリは たくさんあります –ダウンロード処理 –プログレスダイアログ処理 2
  • 4. ショットカットで操作してみましょう 操作 ショートカット 画面の回転 (前へ) Ctrl + F11 画面の回転(次へ) Ctrl + F12 ネットワーク切替 F8 フルスクリーンモード Alt + Enter トラックボール F6 トラックボール Delete (キー押下中) 4
  • 6. スクリーンショットや着呼が可能 • C:¥android¥android-sdk¥tools¥ddms.bat – キャプチャ – ログ – 接続リセット – 着呼 6
  • 8. ライフサイクル モデル • Android端末にど のような操作を行う と、どのような経路 をたどるか?を常に 意識しましょう! 8
  • 9. package jp.probsc.test; public void onPause() { super.onPause(); import android.app.Activity; Log.i("trace", “5. onPause"); import android.os.Bundle; } import android.util.Log; public void onStop() { public class MainActivity super.onStop(); extends Activity { Log.i("trace", “6. onStop"); public void onCreate(Bundle state) { } super.onCreate(state); public void onDestroy() { Log.i("trace", “1. onCreate"); super.onDestroy(); } Log.i("trace", “7. onDestroy"); public void onStart() { } super.onStart(); public void onRestoreInstanceState(Bundle state) { Log.i("trace", “2. onStart"); super.onRestoreInstanceState(state); } Log.i("trace", “8. onRestoreInstanceState"); public void onRestart() { } super.onRestart(); public void onSaveInstanceState(Bundle state) { Log.i("trace", “3. onRestart"); super.onSaveInstanceState(state); } Log.i("trace", “9. onSaveInstanceState"); public void onResume() { } super.onResume(); public void onUserLeaveHint() { Log.i("trace", “4. onResume"); super.onUserLeaveHint(); } Log.i("trace", “10. onUserLeaveHint"); } } 9
  • 10. ログ出力と基に表を埋めてみましょう (1) 起動 (2) Back キー (3) Home キー 1. onCreate 2. onStart 4. onResume (4) 回転 (5) 着呼 (6) (3) 後、アイコンタップ (7) 履歴から他アプリ起動 (8) 小メモリにてHomeキー (9) (8) 後、アイコンタップ 10
  • 11. 画面回転に対応するには? • 縦、横のそれぞれでレイアウトファイルを分ける 画面の大きさによって分けるには「layout-hdpi / layout-mdpi / layout-ldpi」などとします。 具体的な解像度に対応するには「layout-480x320 / layout-854x480」などとします。 • 画面向きを固定する <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait"> 縦向固定 <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="landscape"> 横向固定 11
  • 12. 画面固定して destory 呼ばれなくするには? ... (省略) ... AndroidManifest.xml <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".MainActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden"> ... (省略) ... ... (省略) ... MainActivity.java public class MainActivity extends Activity { ... (省略) ... public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); Log.i(“trace”, “onConfigurationChanged called"); } } ... (省略) ... 12
  • 14. ← こんな Toast が表示され 郵便番号検索 れば成功です。 API の利用 「zip.php?zn=9800014」の部分を変更し て結果が変わるか確かめてみましょう。 HttpURLConnection http = null; String city = InputStream in = null; lineStr.substring( try { lineStr.indexOf("city=¥"") + 6, // HTTP GETにてデータを取得 lineStr.indexOf( URL url = new URL( "¥" />¥n<value address=")); "http://zip.cgis.biz/xml/zip.php?zn=9800014"); Toast.makeText(this, city, http = Toast.LENGTH_LONG).show(); (HttpURLConnection)url.openConnection(); } http.setRequestMethod("GET"); } http.connect(); } in = http.getInputStream(); catch (Exception ex) { } // XML の city 属性の値を取得 finally { byte[] line = new byte[1024]; try { while (true) { if (http != null) http.disconnect(); int size = in.read(line); if (in != null) in.close(); if (size <= 0) break; } catch (Exception e) { String lineStr = new String(line); } if (lineStr.contains("city=")) { } ネットにアクセスするため、AndroidManifest.xmlに下記パーミッションを追加しましょう <uses-permission android:name="android.permission.INTERNET" /> 14
  • 15. 非同期処理 protected Long doInBackground( String... params) { AsyncTask for (int i = 0; i < 10; i++) { if (isCancelled()) break; ... (省略) ... SystemClock.sleep(1000); publishProgress((i + 1) * 10); public void onCreate(Bundle state) { } super.onCreate(state); return 0L; new MyAsyncTask().execute(""); } } protected void onProgressUpdate( Integer... values) { public class MyAsyncTask extends dialog.setProgress(values[0]); AsyncTask<String, Integer, Long> { } ProgressDialog dialog; protected void onCancelled() { protected void onPreExecute() { dialog.dismiss(); dialog = new ProgressDialog(MainActivity.this); new AlertDialog.Builder(MainActivity.this) dialog.setTitle("Loading data..."); .setMessage("キャンセル") dialog.setProgressStyle( .setPositiveButton("OK", null).create().show(); ProgressDialog.STYLE_HORIZONTAL); } dialog.setOnCancelListener( new OnCancelListener() { protected void onPostExecute(Long result) { public void onCancel(DialogInterface arg) { dialog.dismiss(); MyAsyncTask.this.cancel(true); new AlertDialog.Builder(MainActivity.this) } .setMessage("完了!") }); .setPositiveButton("OK", null).create().show(); dialog.setMax(100); } dialog.setProgress(0); } dialog.show(); } ... (省略) ... 15
  • 16. 本日の課題 • じゃんけんゲームの改善 – 画面回転しても影響がないようにライフサイクルの観 点から修正しましょう – メモリ領域が足りなくなっても破棄されないように修正 しましょう • EditTextに郵便番号を入力し、Buttonを押下 にて「AsyncTask + 郵便番号検索API」を起 動し、町の名前をTextViewに表示しましょう 16