LookupActivity学習ノート


LookupActivityはAndroid-SDKのsampleです.
一、onNewIntent(Intent intent)方法
この方法はactivityの保護タイプの方法で、利
既存のActivityで他のIntentを処理する場合はonNewIntentで処理できます.通常は検索要求のあるactivityで使用されますが、そのactivityにはいくつかのintent-filterがあり、この方法が呼び出される前提があります.
a、このactivityは以下の属性android:launchMode=「singleTop」を設定します.
b、activityはすでにスタックの先端にあり、他の方法でacitvityを再起動したときに検索などに呼び出され、oncreate()メソッドは呼び出されません.
この例ではonNewIntent(Intent intent)はすべてのIntentを処理するために使用され、oncreate()メソッドではonNewIntent(getIntent()が呼び出されたと考えられる.
public void onNewIntent(Intent intent) {
        final String action = intent.getAction();
        if (Intent.ACTION_SEARCH.equals(action)) {
            // Start query for incoming search request
            String query = intent.getStringExtra(SearchManager.QUERY);
            startNavigating(query, true);

        } else if (Intent.ACTION_VIEW.equals(action)) {
            // Treat as internal link only if valid Uri and host matches
            Uri data = intent.getData();
            if (data != null && ExtendedWikiHelper.WIKI_LOOKUP_HOST
                    .equals(data.getHost())) {
                String query = data.getPathSegments().get(0);
                startNavigating(query, true);
            }
        } else {
            // If not recognized, then start showing random word
            startNavigating(null, true);
        }
    }

二、URIデータマッチング
1つのIntentは、URIを介してターゲットコンポーネントに外部データを運ぶことができる.ノードでは、ノードを介して外部データが一致します.
mimeTypeプロパティは、外部データを運ぶデータ型を指定し、schemeはプロトコルを指定し、host、port、pathはデータの位置、ポート、パスを指定します.次のようになります.
android:host="host"android:port="port"android:path="path"/>
Intent Filterでこれらの属性が指定されている場合、URIデータの一致はすべての属性が一致した場合にのみ成功します.
この例ではString.format("$1", WIKI_AUTHORITY, WIKI_LOOKUP_HOST)));リンクを<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/lookup_search" android:title="@string/lookup_search" android:icon="@android:drawable/ic_menu_search" /> <item android:id="@+id/lookup_random" android:title="@string/lookup_random" android:icon="@drawable/ic_menu_shuffle" /> <item android:id="@+id/lookup_about" android:title="@string/lookup_about" android:icon="@android:drawable/ic_menu_help" /> </menu> public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.lookup, menu); return true; } 四、在瑞亚乌特法尔埋埋上AlerDialog的protected void showAbout(){ // Inflate the about message contents View messageView = getLayoutInflater().inflate(R.layout.about, null, false); // When linking text, force to always use default color. This works // around a pressed color state bug. TextView textView = (TextView) messageView.findViewById(R.id.about_credits); int defaultColor = textView.getTextColors().getDefaultColor(); textView.setTextColor(defaultColor); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setIcon(R.drawable.app_icon); builder.setTitle(R.string.app_name); builder.setView(messageView); builder.create(); builder.show(); }五,控制在OnKeyDown活动中恢复基的克里克频率,如果连续克里克比0.5秒短的话,回到戴斯克托普的private long mLastPress=-1; public boolean onKeyDown(int keyCode, KeyEvent event) { // Handle back key as long we have a history stack if (keyCode == KeyEvent.KEYCODE_BACK && !mHistory.empty()) { // Compare against last pressed time, and if user hit multiple times // in quick succession, we should consider bailing out early. long currentPress = SystemClock.uptimeMillis(); if (currentPress - mLastPress < DateUtils.SECOND_IN_MILLIS / 2) { return super.onKeyDown(keyCode, event); } mLastPress = currentPress; // Pop last entry off stack and start loading String lastEntry = mHistory.pop(); startNavigating(lastEntry, false); return true; } // Otherwise fall through to parent return super.onKeyDown(keyCode, event); }六、AsyncTask抽象クラスの使用方法http://www.youcanmobile.cn/bbs/viewthread.php?tid=54&extra=page%3D1
七、strings.xmlで配列を定義する
Javaでコードで呼び出す:context.getResources().getStringArray(R.array.month_names)
   
<string-array name="month_names">
        <item>January</item>
        <item>February</item>
        <item>March</item>
        <item>April</item>
        <item>May</item>
        <item>June</item>
        <item>July</item>
        <item>August</item>
        <item>September</item>
        <item>October</item>
        <item>November</item>
        <item>December</item>
    </string-array>

八、デスクトップのwidgetをクリックすると、activityがポップアップされる
Intent defineIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(definePage));
                PendingIntent pendingIntent = PendingIntent.getActivity(context,
                        0 /* no requestCode */, defineIntent, 0 /* no flags */);
                RemoteViews.setOnClickPendingIntent(R.id.widget, pendingIntent);
//R.id.widget          id