TabHost 内的 ActivityGroup 首次运行后不显示内容

发布于 2024-12-05 07:52:23 字数 2132 浏览 0 评论 0原文

我对 ActivityGroup 有疑问。我的应用程序有 4 个选项卡,其中 2 个具有 ActivityGroup 和另外 2 个简单的活动。问题是,首次运行应用程序内容后正确显示,并且当通过后退按钮离开应用程序并返回时,具有活动组的选项卡不显示任何内容,包括菜单。而具有简单活动的选项卡可以正常工作。 你有什么想法吗?


好的,某种代码) 设置此选项卡:

private TabSpec getFrontPageTab() {

        Intent intent = new Intent(context, ActivityGroupHome.class);
        return tabHost
                .newTabSpec("home")
                .setIndicator(
                        getTabView(R.drawable.tabbar_home, "str_home"))
                .setContent(intent);

    }

ActivityGroupHome:

public class ActivityGroupHome extends ActivityGroupBase {

@Override 
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    ActivityUtils activityUtils = ActivityUtils.getInstance(this);

    activityUtils.addActivityGroup("Home", this);
    activityUtils.startHomeActivity("Home");

} 

}

来自 ActivityUtils 的方法:

public void startHomeActivity(String activityGroupName) {

    if (activityGroupName != null) {

        startHomeActivityForActivityGroup(activityGroupName);

    } else {

        Intent intent = new Intent(context, AsyncMainActivity.class);
        // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(intent);

    }

}

private void startHomeActivityForActivityGroup(String activityGroupName) {

    ActivityGroupListItem activityGroupItem = activityGroups
            .findGroupByName(activityGroupName);

    if (activityGroupItem != null) {

        Intent intent = new Intent(activityGroupItem.activityGroup,
                AsyncMainActivity.class);

        intent.putExtra(ACTIVITY_GROUP_NAME, activityGroupItem.name);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        View view = activityGroupItem.activityGroup
                .getLocalActivityManager().startActivity("Home", intent)
                .getDecorView();
        activityGroupItem.activityGroup.setContentView(view);
        activityGroupItem.stack.add("Home");

    }

}

I have issue with ActivityGroup. My app has 4 tabs, 2 of which has ActivityGroup and 2 more simple activity. The problem is that after first run of app content is shown properly, and when leave app through back button and return, tabs with activity group dont shown any content, including menus. While tabs with simple activity work properly.
D'you have any ideas?


Ok, some sort of code)
Setting this tab:

private TabSpec getFrontPageTab() {

        Intent intent = new Intent(context, ActivityGroupHome.class);
        return tabHost
                .newTabSpec("home")
                .setIndicator(
                        getTabView(R.drawable.tabbar_home, "str_home"))
                .setContent(intent);

    }

ActivityGroupHome:

public class ActivityGroupHome extends ActivityGroupBase {

@Override 
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

    ActivityUtils activityUtils = ActivityUtils.getInstance(this);

    activityUtils.addActivityGroup("Home", this);
    activityUtils.startHomeActivity("Home");

} 

}

Methods from ActivityUtils:

public void startHomeActivity(String activityGroupName) {

    if (activityGroupName != null) {

        startHomeActivityForActivityGroup(activityGroupName);

    } else {

        Intent intent = new Intent(context, AsyncMainActivity.class);
        // intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(intent);

    }

}

private void startHomeActivityForActivityGroup(String activityGroupName) {

    ActivityGroupListItem activityGroupItem = activityGroups
            .findGroupByName(activityGroupName);

    if (activityGroupItem != null) {

        Intent intent = new Intent(activityGroupItem.activityGroup,
                AsyncMainActivity.class);

        intent.putExtra(ACTIVITY_GROUP_NAME, activityGroupItem.name);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        View view = activityGroupItem.activityGroup
                .getLocalActivityManager().startActivity("Home", intent)
                .getDecorView();
        activityGroupItem.activityGroup.setContentView(view);
        activityGroupItem.stack.add("Home");

    }

}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文