3

これのエラーは何ですか?LocalActivityManager で次のような警告が表示されます。

タイプ LocalActivityManager は非推奨です

コードは次のとおりです。

import android.os.Bundle;
import android.app.Activity;
import android.app.LocalActivityManager; **// Showing Cancel Warning**
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;


public class MainActivity extends Activity {


TabHost tabHost;
@SuppressWarnings("deprecation")
LocalActivityManager mLocalActivityManager; **// Showing Cancel Warning**

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    initTabs(savedInstanceState);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}

@Override
protected void onResume() {
    mLocalActivityManager.dispatchResume(); 
    super.onResume();
}

@Override
protected void onPause() {
    mLocalActivityManager.dispatchPause(isFinishing());
    super.onPause();
}

@SuppressWarnings("deprecation")
private void initTabs(Bundle savedInstanceState) {
    tabHost = (TabHost) findViewById(android.R.id.tabhost);     // The activity TabHost
    mLocalActivityManager = new LocalActivityManager(this, false);
    mLocalActivityManager.dispatchCreate(savedInstanceState);
    tabHost.setup(mLocalActivityManager);

    TabHost.TabSpec spec;                               // Resusable TabSpec for each tab
    Intent intent;                                      // Reusable Intent for each tab        

    intent = new Intent("com.plastemart.plastemartandroid");
    spec = tabHost.newTabSpec("text").setIndicator("Latest")
                  .setContent(intent);
    tabHost.addTab(spec);      **// Getting Error Unfortunitly Application Stopped...Why?**

    intent = new Intent("com.plastemart.plastemartandroid");
    spec = tabHost.newTabSpec("text").setIndicator("Latest")
                  .setContent(intent);
    tabHost.addTab(spec);


    intent = new Intent("com.plastemart.plastemartandroid");
    spec = tabHost.newTabSpec("text").setIndicator("Latest")
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent("com.plastemart.plastemartandroid");
    spec = tabHost.newTabSpec("text").setIndicator("Latest")
                  .setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(4);
}

私のXMLは以下の通りです

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
tools:context=".MainActivity" >

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="36dp"
    android:background="@drawable/bg_plastemart_title" >

    <TextView
        android:id="@+id/textViewTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Plastemart.Com"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#ffffff" />
</RelativeLayout>


<TabHost
        android:id="@android:id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >

            <HorizontalScrollView
                android:id="@+id/horizontalScrollView1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fillViewport="true"
                android:scrollbars="none" >

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >
                </TabWidget>
            </HorizontalScrollView>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent" />

            <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
            </LinearLayout>

            <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
            </LinearLayout>

            <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" >
            </LinearLayout>

        </LinearLayout>
</TabHost>

どこが間違っていますか?私はAndroidの初心者です。解決策が見つかった場合は、詳細に説明してください。インターネットで手順と解決策を見つけて上記のコードを書きましたが、過去4日間ここで立ち往生しています。私を助けてください。

4

1 に答える 1

3

このクラスは API レベル 13 で廃止されました。Fragment と FragmentManager を使用することをお勧めします。Fragment および FragmentManager API を使用する予定がない場合は、この警告メッセージを受け入れる必要があります。

これは単なる警告メッセージであり、エラー メッセージではないことをご理解ください。だから、あなたはまだこれと一緒に暮らすことができます。ただし、推奨されるオプションは Fragment および FragmentManager API を使用することです

非推奨クラスの詳細については、http://developer.android.com/reference/android/app/LocalActivityManager.html を参照してください

フラグメント - http://developer.android.com/reference/android/app/Fragment.html FragmentManager - http://developer.android.com/reference/android/app/FragmentManager.html

于 2013-03-15T22:12:48.417 に答える