Android:多个TabActivities问题

时间:2010-12-20 16:03:52

标签: android android-layout android-manifest android-tabhost

我已经在这个问题上丢失了2天,请提供任何帮助。 我有一个Android应用程序,显示2个Android活动图标:“Comp 1”和“Comp 2”。 “Comp 1”和“Comp 2”都显示TabActivities及其中的选项卡。 问题: 在部署我的应用程序之后,我可以进入“Comp 1”或“Comp 2”TabActivity中的任何一个,但是当我离开活动并且当我尝试输入另一个TabActivity时,显示的选项卡与前一个选项卡相同“ Comp 1“或”Comp 2“它总是取决于我首先开始。 目的: 对于任何“Comp N”,正确打开TabActivities上指定的选项卡(请参阅本文中的代码)。

请允许我显示我的代码。 我将展示AndroidManifest.xml,TabActivity为“Comp 1”,TabActivity为“Comp 2”。它们有点广泛,所以我提前为它们可能包含的任何额外和不必要的信息道歉。我只是不想冒险忘记在第一篇文章中提供任何重要信息。

AndroidManifest.xml(“Comp 1”= MMComponentTabAssembler,“Comp 2”= TabAssembler)

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  android:versionCode="1"
  android:versionName="1.0" 
  android:installLocation="internalOnly"
  package="be.multitel.android.mmnd">
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <uses-library android:name="com.google.android.maps" />
    <activity android:name=".activity.TabAssembler"
              android:label="@string/app_name"
              android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>

            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

        </intent-filter>
    </activity>

        <activity android:name=".activity.NetworkDispatcher1"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.TAB" />
        </intent-filter>
    </activity>

    <activity android:name=".activity.Device"
              android:label="@string/app_test_device_name">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.TAB" />
        </intent-filter>
    </activity>

    <activity android:name=".activity.SMS"
              android:label="@string/sms_app_name">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.TAB" />
        </intent-filter>
    </activity>

    <activity android:name=".activity.NetworkDispatcherActivity"
              android:label="@string/test_network_dispatcher_app_name">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.TAB" />
        </intent-filter>
    </activity>

    <!-- Begin :: Code for standard MMComponentTabAssembler tab view.
        Use this code to include new components activities that extend from MMSuperComponent.
    -->
    <activity android:name=".activity.MMComponentTabAssembler"
              android:label="Comp 1"
              android:theme="@android:style/Theme.NoTitleBar">            
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
    <activity android:name=".activity.GPS"
              android:label="GPS">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.TAB" />
        </intent-filter>
    </activity>
    <activity android:name=".activity.GPSPreferences"
              android:label="GPSPrefs">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.TAB" />
        </intent-filter>
    </activity>
    <activity android:name=".activity.StandardSetupActivity"
              android:label="Setup">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.TAB" />
        </intent-filter>
    </activity>
    <!-- End :: Code for standard MMComponentTabAssembler tab view. -->

    <service android:exported="true" android:name=".service.NetworkDispatcherService" android:process=":remote">
        <intent-filter>
            <action android:name="NetworkDispatcherService">
            </action>
        </intent-filter>
    </service>
    <service android:exported="true" android:name=".service.NetHubService" android:process=":remote"/>


    <receiver android:name=".service.utils.NetworkListener"> 
        <intent-filter> 
            <action android:name=
                "android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name=
                "android.provider.Telephony.SMS_RECEIVED" />
            <action android:name=
                "be.multitel.android.mmnd.service.utils.SocketListener.ACK_RECEIVED" />
        </intent-filter> 
    </receiver>

    <receiver android:name=".service.utils.MMNetworkDispatcherReceiver" > 
        <intent-filter> 
            <action android:name=
                "android.net.conn.CONNECTIVITY_CHANGE" />
            <action android:name=
                "CONNECTIVITY_CHANGE" />    
            <action android:name=
                "android.provider.Telephony.SMS_RECEIVED" />
            <action android:name=
                "be.multitel.android.mmnd.service.utils.SocketListener.ACK_RECEIVED" />
        </intent-filter> 
    </receiver>

    <receiver android:name=".service.utils.MMReceiver" > 
        <intent-filter>
        <action android:name="ACTION_MM_CONNECT" />
        <action android:name="ACTION_MM_DISCONNECT" />
        <action android:name="ACTION_EVENT_CMD_DISPATCHER_ACCESREQ" />
        <action android:name="ACTION_EVENT_CMD_DISPATCHER_ACCESRELEASE" />
        <action android:name="ACTION_EVENT_CMD_DISPATCHER_ACCESINFOREQ" />
        <action android:name="ACTION_EVENT_CMD_DISPATCHER_BWINFOREQ" />
        <action android:name="ACTION_EVENT_CMD_DISPATCHER_LATENCYINFOREQ" />
        <category android:name="COMPONENT_CATEGORY_GPS"/>
        </intent-filter>
    </receiver>

</application>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

“Comp 1”TabActivity = MMComponentTabAssembler

public class MMComponentTabAssembler extends TabActivity {

public static final String TAG = MMComponentTabAssembler.class.getName();

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.standard_tabbed_pane);
    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    //Multimodal component tab 
    intent = new Intent().setClass(this, GPS.class);
    intent.addCategory(Const.COMPONENT_CATEGORY_GPS); //Used to produce Intents to the MMComponent
    intent.addCategory(Const.ACTIVITY_CATEGORY_GPS); //Used to consume Intents on the BroadcastReceiver associated to the Activity

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("gps").setIndicator("GPS",
                      res.getDrawable(R.drawable.ic_tab_gps))
                  .setContent(intent);
    tabHost.addTab(spec);

    //preferences tab
    intent = new Intent().setClass(this, GPSPreferences.class);

    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("gpsPrefs").setIndicator("GPSPrefs",
                      res.getDrawable(R.drawable.ic_tab_gpsprefs))
                  .setContent(intent);
    tabHost.addTab(spec);

    //standard setup tab
    intent = new Intent().setClass(this, StandardSetupActivity.class);
    intent.addCategory(Const.COMPONENT_CATEGORY_GPS); //Used to produce Intents to the MMComponent
    intent.addCategory(Const.ACTIVITY_CATEGORY_GPS); //Used to consume Intents on the BroadcastReceiver associated to the Activity
    spec = tabHost.newTabSpec("standard_setup_tab").setIndicator("Setup",
                    res.getDrawable(R.drawable.ic_tab_standard_setup))
                  .setContent(intent);
    tabHost.addTab(spec);
    tabHost.setCurrentTab(0);
}

@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG,"Activity group lifecicle :: onResume().");
}

@Override
protected void onPause() {
    super.onPause();
    Log.d(TAG,"Activity group lifecicle :: onPause().");
}

@Override
protected void onStop() {
    super.onStop();
    Log.d(TAG,"Activity group lifecicle :: onStop().");
}

@Override
protected void onDestroy() {
    super.onDestroy();
    Log.d(TAG,"Activity group lifecicle :: onDestroy().");
}   

}

“Comp 2”TabActivity = TabAssembler

public class TabAssembler extends TabActivity  {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_tab);
    Resources res = getResources(); // Resource object to get Drawables
    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    intent = new Intent().setClass(this, NetworkDispatcher1.class);
    // Initialize a TabSpec for each tab and add it to the TabHost
    spec = tabHost.newTabSpec("netword_dispatcher").setIndicator("NDispatcher",
                      res.getDrawable(R.drawable.ic_tab_mmnd))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, Device.class);
    spec = tabHost.newTabSpec("test_device").setIndicator("Test Device",
                    res.getDrawable(R.drawable.ic_tab_test_device))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, SMS.class);
    spec = tabHost.newTabSpec("test_sms").setIndicator("SMS",
                    res.getDrawable(R.drawable.ic_tab_sms))
                  .setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, NetworkDispatcherActivity.class);
    spec = tabHost.newTabSpec("test_network_dispatcher").setIndicator("Test ND",
                    res.getDrawable(R.drawable.ic_tab_test_network_dispatcher))
                  .setContent(intent);
    tabHost.addTab(spec);
    tabHost.setCurrentTab(3);

}

}

1 个答案:

答案 0 :(得分:2)

只有一项活动设定   其他人应该设置别的东西,比如 然后只有一个活动分配了图标。