Android:多个TabActivities问题

发布于 2024-10-08 04:10:35 字数 11355 浏览 0 评论 0原文

我已经在这个问题上浪费了 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、“Comp 1”的 TabActivity 和“Comp 2”的 TabActivity。它们有点广泛,因此对于它们可能包含的任何额外和不必要的信息,我提前表示歉意。我只是不想冒险忘记在第一篇文章中提供任何重要信息。

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);

}

}

I have already lost 2 days in this problem, please provide any help you can.
I have an Android application which displays 2 Android Activity icons: "Comp 1" and "Comp 2".
Both "Comp 1" and "Comp 2" shows TabActivities with tabs within.
Problem:
Right after deploying my application, I can enter into any of "Comp 1" or "Comp 2" TabActivity, but when I leave the activity and when I try to enter the other TabActivity, the tabs shown are the same from the previous one "Comp 1" or "Comp 2" it always depends on which I start first.
Objective:
For any of the "Comp N", open correctly the tabs assigned on the TabActivities(see code on this post).

Please, allow me to show my code.
I will show AndroidManifest.xml, TabActivity for "Comp 1" and TabActivity for "Comp 2". They're a bit extensive, so I apologize in advance for any extra and unnecessary info they may contain. I just didn't want to take risk to forget to provide any important information on the first post.

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);

}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在梵高的星空下 2024-10-15 04:10:35

只有一项活动设置

其他人应该设置其他东西,例如

然后只有一个活动分配了该图标。

Only one of activity set

And others should set something else, such as

Then only one activity assigned the icon.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文