2011年6月11日土曜日

GPS機能活用、スマホに仮想通貨やクーポン配信 コンビニなど集客狙う

 スマートフォン(高機能携帯電話)に組み込まれた全地球測位システム(GPS)の機能を使ったサービスが相次ぎ登場している。電通が位置情報を活用したゲーム配信を86カ国・地域で始めたほか、コンビニエンスストアや飲食店が近場の客だけに割引情報を配信するサービスに参入している。スマートフォンの世界出荷数がパソコンを初めて超えるなど普及の加速が背景にあり、新たなマーケティング手段として広がりそうだ。

2011年6月10日金曜日

Android on the Diamond and Raphael / iPod Touch 1G

http://forum.xda-developers.com/wiki/index.php?title=Linux_on_Raphael
http://xdandroid.com/wiki/Main_Page
http://forum.xda-developers.com/wiki/index.php?title=HTC_Raphael

iPod Touch 1G
http://www.idroidproject.org/

HP、米国で webOS タブレット「TouchPad」を7月に発売

米国 Hewlett-Packard(HP)は2011年6月9日、米国で新型タブレット「HP TouchPad」の Wi-Fi 版を7月1日より販売すると発表した。英国、アイルランド、フランス、ドイツではその数日後、カナダでは7月中旬に発売する予定。北米と欧州で購入予約の受付を6月19日に開始する。米国における価格は、ストレージ容量 16GB モデルが499.99ドル、32GB モデルが599.99ドル。

イタリア、スペイン、オーストラリア、香港、ニュージーランド、シンガポールでも20110年後半より販売するとしている。

さらに HP は、米国 AT&T 携帯電話ネットワーク対応版の販売を2011年夏の終わりに開始する計画も明らかにした。詳細は改めて発表する。

TouchPad は、モバイル OS「HP webOS」ベースのタブレット端末。9.7インチ(1024×768ピクセル表示)のマルチタッチ対応画面を搭載する。無線 LAN(Wi-Fi)のほか、Bluetooth による無線データ通信も可能。ビデオ会議などに使える130万画素のカメラやスピーカー、イヤホン/マイク端子などを備える。

プロセッサは、動作周波数 1.2GHz の米国 QUALCOMM 製「Snapdragon dual-CPU APQ8060」。サイズは幅190×高さ240×厚さ13.7mm で、重さは約740g。

HP、米国で webOS タブレット「TouchPad」を7月に発売

Androidアプリも機種依存

 2011年のスマートフォン夏モデルで顕著なのが、「ワンセグ、赤外線、おサイフケータイ」といった全部入りの端末。グローバルプラットフォームのAndroidを搭載するスマートフォンは世界共通が基本と思われているが、日本のように独自のエッセンスを加える流れも加速している。さらに各社ごとのオリジナルUI(ユーザーインタフェース)の採用や、機種ごとの特殊なハードウエア、細かい仕様の違いなどにより、一見同じように見えるAndroid端末であっても、その中身が異なっているのは事実だ。

 機種依存というと定義が結構広いですが、ガラケー機能を積んだAndroid端末は日本国内でしか通用せず機種依存と言えると思います。GPSやフロントカメラ、G-Sensorのように機種によって積んでいるいないがあるハードウエア要素がありますので、それも機種依存と言えると思います。Android端末の場合、ハードウエア構成が機種ごとに確実に異なるので、ある機種では動くけどある機種では動かないということが平気でおきます。特定の機種でだけアンインストールができなくなるアプリというのも聞いたことがあります。PCの場合、ハードが異なるように見えますが、WintelとMacという規格でがっちり固められているので、ほとんど機種依存は起こしません。iOS(iPhone、iPad、iPod touch)端末の場合、Appleががっちり管理しているので、機種依存はほとんど起こりません。Androidの場合、ある意味野放し状態なので、機種依存は平気で起こすと考えたほうが妥当ではないかと考えます。

2011年6月9日木曜日

Application Startup

When an activity, service, etc. is launched, Android will read your application's AndroidManifest.xml and read the appropriate /manifest/application/@android:name attribute to determine the name of an android.app.Application subclass to load. Once an instance of the specified Application is created, Application.onCreate() is invoked. All MonoDroid applications will specify an Application, and Application.onCreate() is overridden to initialize the Mono runtime.

Once the Application has been created, AndroidManifest.xml is again consulted to find the class name of the activity/service/etc. to launch. For example, the /manifest/application/activity/@android:name attribute is used to determine the name of an Activity to load. For Activities, this type must inherit android.app.Activity, and once the type is loaded the Activity.onCreate(Bundle) method will be invoked; Activity.onCreate(Bundle) is, conceptually, the classic Main() entrypoint method going by a different mechanism.

Android.App.Activity is the equivalent activity base class for managed code, and the Activity.OnCreate(Bundle) method is invoked during activity startup.

This works via the Android Callable Wrapper generated by monodroid.exe during the build process the name of the Android Callable Wrapper name is placed into the /manifest/application/activity/@android:name attribute value within AndroidManifest.xml.

Thus, Android loads and runs the Android Callable Wrapper (ACW), which in turn registers the ACW with the corresponding managed type before invoking the native method, transferring control to the overriden Android.OnCreate() method in managed code.

グーグルPC、2つの死角

 スマートフォン向けOS(基本ソフト)「アンドロイド」で携帯電話市場を席巻している米グーグルが、米マイクロソフトが約9割のシェアを握るパソコン向けOSの市場にも殴り込みをかけた。
 同社が開発した無償OSの「クロームOS」を搭載するノートPC「クロームブック」が6月15日に欧米7カ国で発売される。発売元は韓国サムスン電子と台湾・宏碁(エイサー)である。
 家電量販店などで一般向けに349〜499ドルで販売されるほか、グーグルが企業や教育機関向けにリースプランも用意する。リース料は企業向けが1台につき月額28ドル、教育機関向けは同20ドルという。
 クロームブックは従来のPCにないいくつかの特徴を持つ。
 まず、動作が軽快なことだ。電源を入れてから8秒で起動し、無線LAN(構内情報通信網)や3G(第3世代)通信の機能ですぐにインターネットにアクセスすることが可能。その秘密は、クロームOSがPC側のアプリケーションソフトとしてブラウザーしか搭載していないことにある。搭載するアプリが少ない分、早く動くのだ。
 また、紛失や盗難でデータが漏洩する危険性も少ない。
 クロームOSはブラウザーを使ってネット経由でアプリを利用する「クラウドコンピューティング」専用のOSとして設計されている。文書ファイルなどのデータはいずれも、グーグルが提供するグループウエア「Google Apps(グーグルアップス)」をはじめ、クラウド(サーバー)上のアプリで作成して保存する。端末側にデータを置かない分、安全性は高いというわけだ。
普及するかは未知数
 「ネット回線は高速大容量化し、アプリもどんどんウェブ化している。クロームブックはクラウド専用のネット端末として、従来のPCとは違う新たな市場を開拓できると見ている」。クロームOSの開発に携わるグーグルの及川卓也シニアエンジニアリングマネージャーはこう自信を見せる。
 ただ、業界では「実際に市場に受け入れられるかは未知数」という声も少なくない。
 不安材料の1つは、まず過去に他社の似たような概念のシステムが、普及に至っていないことだ。
 クロームOSのように端末がソフトやデータを持たず、サーバーで管理するシステムを「シンクライアント」と呼ぶ。マイクロソフトや米IBM、米オラクルなども過去にシンクライアントの製品を発売しているが、一部企業や特定機関にしか使われていないのが現状だ。
 2つ目の懸念は価格の問題。クロームブックの300〜500ドルという価格帯は、「ウィンドウズ7」搭載PCと比較しても、飛び抜けて安いわけではない。
 調査会社ガートナージャパンの蒔田佳苗・主席アナリストは「この価格帯には、ネットブックに加えて低価格の大型ノートPCやタブレットPCも割り込んできている。よほどの魅力がなければ、ユーザーの購入動機を生み出すのは難しい」と指摘する。
 PC各社もクロームOSの実力を測りかねているようだ。5月下旬の現時点でサムスンとエイサー以外にクロームブックを発表する動きは見られず、NECや富士通、東芝といった国内大手も静観の姿勢を見せている。「搭載PCの製品化は検討しているが、具体的なことは何も決まっていない」(東芝広報)。
 とはいえ、これまでIT(情報技術)業界を席巻してきたグーグルが自社OSの普及に乗り出してきたインパクトは大きい。「第2のアンドロイド」として広く使われるようになるとすれば、クロームOSの登場は、IT業界の勢力図を塗り替える号砲となる。

ポストPC時代の「Apple対Google」

6日(現地時間)から米Apple社が開催しているWWDC(開発者会議)は、ソフトウェアに重点を置いている。壇上に復帰したスティーブ・ジョブズ最高経営責任者(CEO)は、ハードウェアはApple社に脳と筋肉を提供するが、ソフトウェアは同社の魂だと述べた。

ジョブズCEOが今回のWWDCで提供したストーリーは3つの章に分かれていたが、そのテーマは一貫していた。Apple社は、2010年代のオペレーティング・システム(OS)をめぐる大きな戦いにおいて、自社の地位を確保しようとしているのだ。

WWDCにおける第一章は、Mac OS Xの最新バージョン『Lion』だ。この章の主なポイントは、マルチタッチ機能が増え、App Storeも内蔵されるなど、Mac OSがiOSの多くを採用したというものだ。

第二章はiOS 5だ。今回新しく発表された各機能は、これまではパソコンだけでしか可能でなかった機能を、『iPad』『iPhone』『iPod touch』でも可能にするものだ。たとえばiOS 5を使えば、写真の編集、複雑なメール文書の作成などが可能になる。

つまり、MacはiPadに進化し、iPadのほうは、かつてはMacやPC専用だった機能を実行できるように進化したのだ。

この変化において最も顕著な点は、Apple社がiOS搭載機器をパソコンから「解放」したことだ。設定やアップデートが、パソコンにつながなくても可能になったのだ。このことは、聴衆の開発者たちから盛大な拍手喝采で迎えられた。かつてわたしは、Apple社はパソコンの主な機能を「iPadと同期させること」にしようとしていると冗談を書いたことがあるが、いまやそれさえも超えたことになる。ジョブズCEOはMacを、「もうひとつのモバイル機器に降格させる」とさえ言った。まるで経営の神様ジャック・ウェルチを中間マネージャーに降格するかのようだ。

さて、第三章は『iCloud』だ。ジョブズCEOによると、iCloudは、コンピューターをローカルファイル等から解放するための長い探求が終わったことを示すものだという。

Apple社の戦略は、競合相手と比べてどうなのだろうか。米Google社のクラウドは、Apple社のクラウドよりも徹底している。Apple社はクラウドを自社サービスのハブと見なしているが、Google社の『Chrome OS』では、クラウドをコンピューター自体として扱っている。

米国では6月15日から発売される『Chromebooks』(日本語版記事)では、基本的に超高速ブラウザが実行され、ウェブベースのアプリケーションやサービスによってあらゆるニーズを満たせると想定されている(ただし、わたしが以前Chrome OSをテストしたときに書いたように、Chrome OSは、実はまだほとんど実現されていない高速インフラを想定して設計されている。)

これと比較すると、Apple社のクラウドは控えめだ。ストレージと同期を対象にしており、ストリーミングやリアルタイム、実際のマシンの拡張は対象外だ。Apple社の場合、動作はウェブ上ではなく、アプリケーション内で行われる。

一方で、Google社の計画を複雑にしているのが、もうひとつのOSであるモバイル向け『Android』の存在だ。Androidは、クライアント・アプリケーションを実行するという点でiOSに似ているが、これによって、ウェブ中心というGoogle社の方針との食い違いが生まれているのだ。5月に開催された『Google I/O開発者会議』でも、これら2つのシステム間の不一致は明確だった。イベントの両日に、どちらかのシステムに関する基調講演があり、その後で行われた記者会見では、これらのシステムが競合しない理由について、各チームのリーダーが説得力のない説明を試みていた。

一方、米Microsoft社はどうだろうか。5月30日に開催された技術カンファレンス『D9』では、『Windows』担当プレジデントのスティーブン・シノフスキーが、『Windows 8』の姿を少しだけ見せてくれた。『Mac OS』がインターフェースをiPhoneやiPadから借用しているように、Windows 8では、称賛に値する(ただし、商業的にはまだ証明されていない)『Windows Phone 7』OSの派手なインターフェースが採用されており、過去と大胆に決別したかのように見える。しかし、シノフスキー氏は同時に、このインターフェースは旧スタイルのWindowsのフルバージョンの上に置かれるとも説明した。(Windows 8タブレットの起動時間はどのくらいになるのだろう?) 「ポストPC」の概念は、Microsoft社ではいまだにタブーになっているようだ。

しかし、Microsoft社が認めようと認めまいと、われわれは数年前からポストPC時代に入っている。われわれの問題は、これらの新しいポストPCの機器が、置き換えられるべきPCと、あらゆる点で同じ能力を持つほど進化できていないことにある。Apple社はWWDCで、そのギャップを埋める方向に近づいた。Apple社が持つ信じがたいほどの推進力を考えれば、Appleユーザーたちが後に続くと考えるべきだろう。

フェイスブックの顔認識機能、プライバシー侵害との懸念も

 会員制交流サイト世界最大手の米フェイスブックは、同社の自動顔認識機能が欧州当局などからプライバシーの侵害ではないかとの懸念が示されていることを受け、欧州当局に情報の提供を始めている。

 フェイスブックは「正式な調査」を受けているわけではないとした上で、同社広報は8日、電子メールでロイターに対し、「この機能に関する規制当局からのコメントに留意し、追加情報を当局に提供している。懸念は解消されると確信している」と述べた。

 この顔認識機能は「Tag Suggestions」と呼ばれ、フェイスブック上に新たに投稿された写真に写っている人物を自動で認識し、ユーザーにタグ付けを提案するというもの。過去にタグ付けされた写真と比較して、合致する人物を割り出す仕組み。

 昨年12月に顔認識機能を米国で導入する計画を発表したフェイスブックは7日、「ほとんどの国」でサービスが開始されたことを明らかにした。

 一方、ブルームバーグが8日に報じたところによると、欧州連合(EU)域内各国のデータ保護当局で構成する第29条作業部会のメンバーは、プライバシー規定に抵触する恐れがあるとして、同部会が調査に乗り出す予定だと述べた。

 また、プライバシー保護団体などは、新機能に関する通知が十分でなかったことに加え、タグ付け提案が自動的に有効になっていることに懸念を表明。機能を開始するかどうかはユーザーに委ねるべきだと訴えている。

Android向けコンテンツの著作権を保護——アクロディア、DRMソリューション提供

 アクロディアは、Android向けコンテンツの著作権を保護するDRMソリューション「Acrodea Rights Guard」の提供を開始した。

 Acrodea Rights Guardは、Android上でコンテンツ配信サービスを提供するコンテンツプロバイダ向けのDRMソリューション。コンテンツの配信/管理からDRM機能までをトータルパッケージをASP型サービスとして提供する。

 配信サーバで自動的に暗号化する仕組みで、コンテンツの種類を問わず配信時にDRMを施せる。音楽やゲーム、映像など、アプリ内にあるデジタルデータの著作権も保護でき、配信サーバ上では、コンテンツ配信を管理するための管理機能を利用できる。

 同ソリューションでは、クライアント側の暗号・複合化/モジュール、ライセンス認証サーバ/暗号化機能サーバ、コンテンツ配信サーバを提供。また、コンテンツプロバイダ保有の配信サーバを利用するプランも用意している。

Facebookの自動顔認識によるタグ付け(Tag Suggestions)

 米Facebookは6月7日(現地時間)、昨年7月に発表した自動顔認識機能による写真のタグ付けサジェスト機能「Tag Suggestions」が、ほぼすべてのFacebook提供国で利用できるようになったと発表した。日本でもこの機能が利用できる。

 Tag Suggestionsは、ユーザーが新たに写真を投稿する際、過去に投稿された写真とそれに付けられたタグのデータに基づいてFacebookが割り出した人名タグの候補をユーザーに提示し、タグ付けを促すというものだ。タグを付けられるのはユーザーの友達に限られるが、自分の知らないうちに自分の写った写真にタグ付けされる確率が高くなる。

 Facebookの多くの機能と同様に、タグ候補として自分の名前が表示される機能はデフォルトで有効で、オプトアウトできるようになっている。

 英セキュリティ企業のSophosは、英国でもこの機能が利用できるようになったのを受け、本人の許可なくタグ付けができるFacebookのプライバシー設定に懸念を表明し、Tag Suggestionsで自分の名前が表示されないようにする方法を公式ブログで紹介している。

Facebookの「アカウント」→「プライバシー設定」を選択
「設定をカスタマイズ」を選択
「他のユーザーがシェアする情報」の「写っている写真のタグ付けを提案」で「設定を編集」を選択
「写真:タグ付けの提案」というウィンドウが表示されるので、ウィンドウ内の「有効にする」をクリックし、「無効にする」に変更し、「OK」をクリックする
デフォルトで「有効にする」になっている

 これで、Facebookが提示するタグ候補から自分の名前が排除される。ただし、ユーザーは手動で人名をタグとして記入することはできる。

Google Mapsにバスや電車のリアルタイム運行状況表示機能

 米Googleは6月8日(現地時間)、モバイル版およびデスクトップ版のGoogle Mapsに電車やバスなどの公共交通機関のリアルな運行状況を表示する機能を追加したと発表した。まずは、米国のボストン、ポートランド、サンディエゴ、サンフランシスコとイタリアのトリノ、スペインのマドリードでスタートした。

 Google Mapsでは、既に日本を含む多くの地域で交通機関の時刻表データを参照できるようになっている。Google Maps上の駅のアイコンをタップして表示される詳細データでは「予定出発時刻」が表示され、道案内機能「経路」で電車の発着時刻を確認できる。だが、渋滞や事故などによる遅延情報は反映されない。

 Googleは、地域の交通機関から取得するリアルタイムの運行状況データに基づいて、これらの機能で遅延情報や実際の発着予定を表示するようにした。

 Google Maps上の駅やバス停のアイコンをタップして表示される詳細ページに新たに「Live departures(実際の発着時刻)」が追加された。

 経路検索でも、遅延がある場合は経路候補のリストページでアラートが表示され、各経路の詳細ページでは遅延理由が表示される。

 Gogleは現在、ほかの地域でもサービス開始に向けて交通機関と協力しているという。

IOS5に少しだけ気になること

製品やサービスの機能、質などの面とは関係ないのだが、全体を通して心のどこかに引っかかることがあった。それは従来はパートナー関係を築いてきたデベロッパーが生み出してきた価値の中から、特に一般的な要素をiOSの標準機能(正確にはiOSに標準で組み込まれているアプリケーション)に積極的に組み込んでいることである。

 例えばカメラやSafari、写真(アルバム機能)などにTwitterへの発信機能が付けられているのはご存知の通り。写真に関して言えば、iCloudのフォトストリームと組み合わせることで、人気の写真系フォト共有サービスと同様のことがより簡単に、標準アプリケーションだけで可能になる。TwitterのサポートはOSのAPIとして実装されているので、どんなアプリケーションでも気軽にTwitterの活用が可能となるが、既存サービスは変革を求められる。

 ほかにも事例はあるが、何かのアイディアが広く使われるようになり、OS側でサポートした方が全体の利益になると判断する機能なら、多少の歪みが出たとしてもシステムに取り込むべきだとは思う。しかし、iOSの付加価値を高めてきたのは、既存の人気サービスと人気アプリケーションであることは言うまでもない。視点を変えると、iPhoneやiPadを魅力的に見せる役割は、パートナーであるデベロッパーも担ってきた。

 OSという基盤技術に、アプリケーションレベルの機能を取り込む際には、これまでも色々な問題が起きてきた。Windowsもシステムに各種機能を取り込む過程でさまざまな軋轢を生んできたのは確かだが、デベロッパーに対する配慮はMicrosoftの方があったように思う。少なくとも、突然はしごを外すようなやり方はせず、ケンカをしながらも着地点を捜していた。

 1990年代のコンピュータと今のスマートフォンのビジネス概況は異なるとはいえ、Appleはこのところ、アプリケーション内課金のルール変更やApp Storeへの登録ポリシーの予告なき変更などでも批判に
曝されている。

 iOSの機能強化はユーザー視点では良い面の方が多いのだが、長期的に見るとデベロッパーの離脱へとつながらないかとやや気になり始めている。今のiOSデバイスの稼働数を考えれば、そう簡単には衰退はしないだろう。しかし、こうした思いは年々、つもりゆくものでもある。

IOS5

 iOS 5のアップデートは、簡単に言えばAndroidに盛り込まれている要素が組み込まれただけなのにメジャーアップデートなのか? という声も聞こえてくるが、携帯電話向けのOSはシンプ
ルさも肝要だ。OSの核となる部分のシンプルさは可能な限り維持しながら、機能面での充実を標準装備のアプリケーションで行なうというのは妥当な手法だろう。

 それに大きな変化ではないように見えて、意外にOSのサービスレイヤーは厚くなってきているのではないだろうか。アプリケーション通知を、Androidのドロワーよろしく一覧する機能やTwitter投稿機能のAPI化もあるが、従来は設定や運用のシンプルさを確保するため、徹底してパーソナルコンピュータのコンパニオン機器として位置付けていたiOS搭載機を、パーソナルコンピュータから独立した存在にしようとしているのだから、これは表面上の変化(各種アプリケーションの機能アップやAPI更新)よりも大きな更新であり、十分にメジャーバージョンアップの価値はあると思う。

 iOS(iPhone)的なコンパニオン機器としてのコンセプトを学び、Windows Mobileが持っていた独立したコンピュータとしての要素を捨てることでシンプルさを得たWindows Phone 7とは対象的だ。Android、iOS、そ
れにWindows Phone 7は相互に影響を及ぼし合いながら、それぞれのコンセプトに各種要素を取り入れている。MicrosoftがKIN(SNS利用に特化した携帯電話)やWindows Phone 7で取り組んだSNSのOS統合を、Twitter APIのOS
レベルでのサポートという形でiOS 5取り入れたが、こうした相互作用による進歩は、今後しばらく続いていくはずだ。

2011年6月8日水曜日

Creating Dialogs

A dialog is usually a small window that appears in front of the current Activity. The underlying Activity loses focus and the dialog accepts all user interaction. Dialogs are normally used for notifications that should interupt the user and to perform short tasks that directly relate to the application in progress (such as a progress bar or a login prompt).

The Dialog class is the base class for creating dialogs. However, you typically should not instantiate a Dialog directly. Instead, you should use one of the following subclasses:

AlertDialog

A dialog that can manage zero, one, two, or three buttons, and/or a list of selectable items that can include checkboxes or radio buttons. The AlertDialog is capable of constructing most dialog user interfaces and is the suggested dialog type. SeeCreating an AlertDialog

 below.

ProgressDialog

A dialog that displays a progress wheel or progress bar. Because it's an extension of the AlertDialog, it also supports buttons. See Creating a ProgressDialog below.

DatePickerDialog

A dialog that allows the user to select a date. See the Hello DatePicker tutorial.

TimePickerDialog

A dialog that allows the user to select a time. See the Hello TimePicker tutorial.

If you would like to customize your own dialog, you can extend the base Dialog object or any of the subclasses listed above and define a new layout. See the section on Creating a Custom Dialog below.

A dialog is always created and displayed as a part of an Activity. You should normally create dialogs from within your Activity'sonCreateDialog(int) callback method. When you use this callback, the Android system automatically manages the state of each dialog and hooks them to the Activity, effectively making it the "owner" of each dialog. As such, each dialog inherits certain properties from the Activity. For example, when a dialog is open, the Menu key reveals the options menu defined for the Activity and the volume keys modify the audio stream used by the Activity.

When you want to show a dialog, call showDialog(int) and pass it an integer that uniquely identifies the dialog that you want to display.

When a dialog is requested for the first time, Android calls onCreateDialog(int) from your Activity, which is where you should instantiate theDialog. This callback method is passed the same ID that you passed to showDialog(int). After you create the Dialog, return the object at the end of the method.

Before the dialog is displayed, Android also calls the optional callback method onPrepareDialog(int, Dialog). Define this method if you want to change any properties of the dialog each time it is opened. This method is called every time a dialog is opened, whereasonCreateDialog(int) is only called the very first time a dialog is opened. If you don't define onPrepareDialog(), then the dialog will remain the same as it was the previous time it was opened. This method is also passed the dialog's ID, along with the Dialog object you created inonCreateDialog().

The best way to define the onCreateDialog(int) and onPrepareDialog(int, Dialog) callback methods is with a switch statement that checks the id parameter that's passed into the method. Each case should check for a unique dialog ID and then create and define the respective Dialog. For example, imagine a game that uses two different dialogs: one to indicate that the game has paused and another to indicate that the game is over. First, define an integer ID for each dialog:

Then, define the onCreateDialog(int) callback with a switch case for each ID:

When it's time to show one of the dialogs, call showDialog(int) with the ID of a dialog:

When you're ready to close your dialog, you can dismiss it by calling dismiss() on the Dialog object. If necessary, you can also calldismissDialog(int) from the Activity, which effectively calls dismiss() on the Dialog for you.

If you are using onCreateDialog(int) to manage the state of your dialogs (as discussed in the previous section), then every time your dialog is dismissed, the state of the Dialog object is retained by the Activity. If you decide that you will no longer need this object or it's important that the state is cleared, then you should call removeDialog(int). This will remove any internal references to the object and if the dialog is showing, it will dismiss it.

Using dismiss listeners

If you'd like your application to perform some procedures the moment that a dialog is dismissed, then you should attach an on-dismiss listener to your Dialog.

First define the DialogInterface.OnDismissListener interface. This interface has just one method, onDismiss(DialogInterface), which will be called when the dialog is dismissed. Then simply pass your OnDismissListener implementation to setOnDismissListener().

However, note that dialogs can also be "cancelled." This is a special case that indicates the dialog was explicitly cancelled by the user. This will occur if the user presses the "back" button to close the dialog, or if the dialog explicitly calls cancel() (perhaps from a "Cancel" button in the dialog). When a dialog is cancelled, the OnDismissListener will still be notified, but if you'd like to be informed that the dialog was explicitly cancelled (and not dismissed normally), then you should register an DialogInterface.OnCancelListener with setOnCancelListener().

An AlertDialog is an extension of the Dialog class. It is capable of constructing most dialog user interfaces and is the suggested dialog type. You should use it for dialogs that use any of the following features:

·                                 A title

·                                 A text message

·                                 One, two, or three buttons

·                                 A list of selectable items (with optional checkboxes or radio buttons)

To create an AlertDialog, use the AlertDialog.Builder subclass. Get a Builder with AlertDialog.Builder(Context) and then use the class's public methods to define all of the AlertDialog properties. After you're done with the Builder, retrieve the AlertDialog object with create().

The following topics show how to define various properties of the AlertDialog using the AlertDialog.Builder class. If you use any of the following sample code inside your onCreateDialog() callback method, you can return the resulting Dialog object to display the dialog.

Adding buttons

To create an AlertDialog with side-by-side buttons like the one shown in the screenshot to the right, use theset...Button() methods:

First, add a message for the dialog with setMessage(CharSequence). Then, begin method-chaining and set the dialog to be not cancelable (so the user cannot close the dialog with the back button) with setCancelable(boolean). For each button, use one of the set...Button()methods, such as setPositiveButton(), that accepts the name for the button and a DialogInterface.OnClickListener that defines the action to take when the user selects the button.

Adding a list

To create an AlertDialog with a list of selectable items like the one shown to the right, use the setItems()method:

First, add a title to the dialog with setTitle(CharSequence). Then, add a list of selectable items with setItems(), which accepts the array of items to display and a DialogInterface.OnClickListener that defines the action to take when the user selects an item.

Adding checkboxes and radio buttons

To create a list of multiple-choice items (checkboxes) or single-choice items (radio buttons) inside the dialog, use the setMultiChoiceItems() and setSingleChoiceItems() methods, respectively. If you create one of these selectable lists in the onCreateDialog() callback method, Android manages the state of the list for you. As long as the Activity is active, the dialog remembers the items that were previously selected, but when the user exits the Activity, the selection is lost.

To create an AlertDialog with a list of single-choice items like the one shown to the right, use the same code from the previous example, but replace the setItems() method with setSingleChoiceItems():

The second parameter in the setSingleChoiceItems() method is an integer value for the checkedItem, which indicates the zero-based list position of the default selected item. Use "-1" to indicate that no item should be selected by default.

A ProgressDialog is an extension of the AlertDialog class that can display a progress animation in the form of a spinning wheel, for a task with progress that's undefined, or a progress bar, for a task that has a defined progression. The dialog can also provide buttons, such as one to cancel a download.

Opening a progress dialog can be as simple as calling ProgressDialog.show(). For example, the progress dialog shown to the right can be easily achieved without managing the dialog through theonCreateDialog(int) callback, as shown here:

The first parameter is the application Context, the second is a title for the dialog (left empty), the third is the message, and the last parameter is whether the progress is indeterminate (this is only relevant when creating a progress bar, which is discussed in the next section).

The default style of a progress dialog is the spinning wheel. If you want to create a progress bar that shows the loading progress with granularity, some more code is required, as discussed in the next section.

Showing a progress bar

To show the progression with an animated progress bar:

1.                               Initialize the ProgressDialog with the class constructor, ProgressDialog(Context).

2.                               Set the progress style to "STYLE_HORIZONTAL" with setProgressStyle(int) and set any other properties, such as the message.

3.                               When you're ready to show the dialog, call show() or return the ProgressDialog from theonCreateDialog(int) callback.

4.                               You can increment the amount of progress displayed in the bar by calling either setProgress(int) with a value for the total percentage completed so far or incrementProgressBy(int) with an incremental value to add to the total percentage completed so far.

For example, your setup might look like this:

The setup is simple. Most of the code needed to create a progress dialog is actually involved in the process that updates it. You might find that it's necessary to create a second thread in your application for this work and then report the progress back to the Activity's UI thread with a Handlerobject. If you're not familiar with using additional threads with a Handler, see the example Activity below that uses a second thread to increment a progress dialog managed by the Activity.

 Example ProgressDialog with a second thread

If you want a customized design for a dialog, you can create your own layout for the dialog window with layout and widget elements. After you've defined your layout, pass the root View object or layout resource ID tosetContentView(View).

For example, to create the dialog shown to the right:

1.                               Create an XML layout saved as custom_dialog.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="horizontal"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:padding="10dp"
              >
    <ImageView android:id="@+id/image"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:layout_marginRight="10dp"
               />
    <TextView android:id="@+id/text"
              android:layout_width="wrap_content"
              android:layout_height="fill_parent"
              android:textColor="#FFF"
              />
</LinearLayout>

This XML defines an ImageView and a TextView inside a LinearLayout.

2.                               Set the above layout as the dialog's content view and define the content for the ImageView and TextView elements:

After you instantiate the Dialog, set your custom layout as the dialog's content view with setContentView(int), passing it the layout resource ID. Now that the Dialog has a defined layout, you can capture View objects from the layout with findViewById(int) and modify their content.

3.                               That's it. You can now show the dialog as described in Showing A Dialog.

A dialog made with the base Dialog class must have a title. If you don't call setTitle(), then the space used for the title remains empty, but still visible. If you don't want a title at all, then you should create your custom dialog using the AlertDialog class. However, because an AlertDialog is created easiest with the AlertDialog.Builder class, you do not have access to the setContentView(int) method used above. Instead, you must use setView(View). This method accepts a View object, so you need to inflate the layout's root View object from XML.

To inflate the XML layout, retrieve the LayoutInflater with getLayoutInflater() (or getSystemService()), and then callinflate(int, ViewGroup), where the first parameter is the layout resource ID and the second is the ID of the root View. At this point, you can use the inflated layout to find View objects in the layout and define the content for the ImageView and TextView elements. Then instantiate the AlertDialog.Builder and set the inflated layout for the dialog with setView(View).

Here's an example, creating a custom layout in an AlertDialog:

Using an AlertDialog for your custom layout lets you take advantage of built-in AlertDialog features like managed buttons, selectable lists, a title, an icon and so on.

For more information, refer to the reference documentation for the Dialog and AlertDialog.Builder classes.

http://developer.android.com/guide/topics/ui/dialogs.html