离开TabActivity并正常返回

发布于 2024-12-14 20:42:58 字数 402 浏览 6 评论 0原文

我有一个问题,我有一个使用 TabActivities 的 ActivityGroup。在不同的活动之间切换一切都很顺利。然而,我有一些观点,我不想有标签。他们是完全不同的观点我不想成为活动小组的一部分。

目前,我只需在 ActivityGroupstartActivityFromChild 函数中执行常规 startActivity(intent) 即可离开活动组。

这是可行的,但是当我点击后退按钮时,尽管我返回到之前的 TabActivity,但 onCreate() 却被调用了两次。

如何正确地将 TabActivity 保留到常规 Activity 然后正确返回它?

I have an issue where I have an ActivityGroup using TabActivities. Everything works great switching between different activities. However, I have some views that I don't want to have tabs. They are completely different views I don't want to be part of the activity group.

Currently I'm leaving the activity group by just doing a regular startActivity(intent) in the ActivityGroup's startActivityFromChild function.

This works, but when I hit the back button, though I return to the previous TabActivity, onCreate() is called twice as a result.

How can I properly leave a TabActivity to a regular Activity then properly go back to it?

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

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

发布评论

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

评论(2

雪若未夕 2024-12-21 20:42:58

我不确定,但我敢打赌 onCreate 会被故意调用两次。也许一次是通过组,然后是通过实际的选项卡。这种行为实际上破坏了您的代码吗?

也许将您不想运行两次的代码移至单独的函数。然后设置一个标志来决定是否/何时运行它。

public class YourActivity {

    private boolean i_feel_like_it = true;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            runIfYouFeelLikeIt();
    }


    private void runIfYouFeelLikeIt() {
        if(i_feel_like_it) {
             doIt();
             i_feel_like_it = false;
        }
    }
}

I don't know for sure, but I bet onCreate is being called twice intentionally. Perhaps once by the Group and then by the actual Tab. Is this behavior actually breaking your code?

Perhaps move to a separate function the code that you don't want to run twice. Then set a flag to decide if/when you want to run it.

public class YourActivity {

    private boolean i_feel_like_it = true;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            runIfYouFeelLikeIt();
    }


    private void runIfYouFeelLikeIt() {
        if(i_feel_like_it) {
             doIt();
             i_feel_like_it = false;
        }
    }
}
爱已欠费 2024-12-21 20:42:58

固定的。该问题与 getLocalActivityManager().startActivity(newRecord.id, newRecord.intent); 有关在不同功能的活动组中被调用两次。

Fixed. The issue had to do with getLocalActivityManager().startActivity(newRecord.id, newRecord.intent); being called twice in the activity group in different functions.

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