单击 TabActivity 的某些 TabSpec 时恢复主 Activity

发布于 2025-01-08 15:04:12 字数 831 浏览 3 评论 0原文

我的申请中有两项主要活动。我们称它们为“主页”和“选项卡”。

在主页中有一个搜索编辑框和结果列表。

选项卡中有 2 个重要选项卡:产品详细信息和类似产品列表。

问题是您可以通过单击以下内容轻松循环:productA ->类似->产品B->类似->产品A-> ...

一切都很好,直到您想再次返回主页进行新搜索为止。使用后退按钮需要点击几下。

选项卡在清单中具有 android:noHistory="true" 属性。

我想出的是在选项卡中添加第三个选项卡,该选项卡应该重新打开主页活动。我刚刚重写了 onResume 方法。

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    Intent myIntent = new Intent(getBaseContext(), Home.class);
    startActivityFromChild(this, myIntent, 0);  
    finishFromChild(this);
}

结果是,单击“搜索”选项卡会启动一个新的“主页”活动(搜索字段为空),如果我单击“后退”按钮,它会再次将我重定向到“主页”活动,但这次搜索字段中有文本。

我需要的是在单击搜索选项卡后搜索字段填充最近输入的文本的活动。此外,单击“主页”活动中的后退按钮不应重新打开它,而只是关闭应用程序。

顺便提一句。如果您有比这个附加搜索选项卡更好的主意,请与我分享:)

干杯

I have 2 main activities in my application. Lets call them Home and Tabs.

In Home there is a search EditBox and a list of the results.

In Tabs there are 2 significant tabs: details of a product and a list of similar products.

The problem is that you can easily loop here by clicking: productA -> similar -> productB -> similar -> productA -> ...

It's all fine until you want to go back to the Home again for a new search. Using back button will require a few clicks.

Tabs has the android:noHistory="true" attribute in manifest.

What I figured out was to add a third tab to Tabs which should reopen Home activity. I just overridden the onResume method.

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    Intent myIntent = new Intent(getBaseContext(), Home.class);
    startActivityFromChild(this, myIntent, 0);  
    finishFromChild(this);
}

The result is that clicking search tab starts a new Home activity (search field is empty) and if I than click back button it redirects me to Home activity once more, but this time there is text in the search field.

What I need is the activity with search field filled with recently typed text just after search tab is clicked. Also clicking back button in Home activity should not reopen it but just close the application.

Btw. If you have a better idea than this additional search tab please share with me :)

Cheers

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

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

发布评论

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

评论(1

心的位置 2025-01-15 15:04:12

这很简单:

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    finish();
}

It was as easy as:

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

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