Androidプログラマへの道 〜 Moonlight 明日香 〜 - ランチャーアクティビティを作成する
ランチャーアクティビティ(LauncherActivity)は, 指定したインテントを扱えるアクティビティの一覧に表示する.



ランチャーアクティビティ

  • res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  >
  <ListView android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:drawSelectorOnTop="false"
    />
</LinearLayout>
  • Launcher01.java
    • アクティビティは, LauncherActivityクラスを継承する.
    • getTargetIntentメソッドをオーバーライドして実装し, 戻り値としてインテントのインスタンスを返す.
    • インテントのURIに, 下記のようなURIを指定する.
<< URIの一例 >>
Uri対象
http://web_addressブラウザhttp://www.google.com
tel:phone_number電話tel:080-0001-0001
content://contacts/people連絡先content://contacts/people/
geo:latitude,longitude地図geo:0,0?q=Osaka
package com.moonlight_aska.android.launcher01;

import android.app.LauncherActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class Launcher01 extends LauncherActivity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
  }

  @Override
  protected Intent getTargetIntent() {
    // TODO Auto-generated method stub
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=Osaka"));
    return intent;
  }
}

Googleマップを選択すると, 指定した場所の地図が表示される.