有什么好的解决方案可以在 TabActivity 中分别搜索选项卡中的每个活动吗?
我的活动导航有问题,搜索效果很好。
活动层次结构如下所示:
/ MyListActivityA -- ItemActivityA
MainActivity -- MyTabActivity -- MyListActivityB -- ItemActivityB
\ MyListActivityB -- ItemActivityC
TabActivity 中的选项卡是使用 Intents 和 MyListActivity 创建的。
MyListActivities 在清单中声明如下:
<activity
android:name=".views.OrderListView">
<intent-filter>
<action
android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable_orders" />
</activity>
每个 MyListActivity 都有自己的 SearchRecentSuggestionsProvider。
第一个解决的问题
当对任何 MyListActivity 调用搜索时,我得到了MyTabActivity外部的活动。因此实现了重定向到 MyTabActivity。
在 MyListActivity 的 onCreate() 中检查意图操作。如果是,
Intent.ACTION_SEARCH
则启动 TabActivity 并完成当前操作,如下所示:
if(Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
intent.setClass(context, MyTabActivity.class);
intent.setAction(MyTabActivity.ACTION_SEARCH_PROXY);
Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
if(appData != null) {
intent.putExtras(appData);
}
intent.putExtra(Constants.ACTIVITY_TYPE, activityType);
intent.putExtra(ActivityTabView.EXTRA_SEARCH_QUERY, query);
context.startActivity(intent);
context.finish();
}
当 MyListActivity find 时,
ActivityTabView.EXTRA_SEARCH_QUERY
它会在列表上进行搜索查询。问题解决了。
第二个已解决的问题
单击“后退”按钮会清除搜索查询 - 没关系。但再次单击“返回”会显示过去的搜索。
这就是为什么我将 noHistory 添加到 MyTabActivity 中:
<activity
android:name=".views.MyTabActivity"
android:noHistory="true">
</activity>
第三个未解决的问题
例如,现在从 MyListActivityA 转到 ItemActivityA 并单击“返回”会重定向到 MainActivity。由于 noHistory 参数,我无法返回 MyTabActivity。
有没有什么好的解决方案可以使用Android在TabActivity中分别搜索选项卡中的每个活动?
I have problem with Activities navigation, searching works good.
Activities hierarchy looks like that:
/ MyListActivityA -- ItemActivityA
MainActivity -- MyTabActivity -- MyListActivityB -- ItemActivityB
\ MyListActivityB -- ItemActivityC
Tabs in TabActivity are created using Intents with MyListActivity.
MyListActivities are declared in manifest like below:
<activity
android:name=".views.OrderListView">
<intent-filter>
<action
android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable_orders" />
</activity>
Every MyListActivity has own SearchRecentSuggestionsProvider.
First resolved problem
When invoked search on any of MyListActivity I got the activity outside the MyTabActivity. Therefore implemented redirecting to MyTabActivity.
In onCreate() of MyListActivity intent action is checked. If it's
Intent.ACTION_SEARCH
then start TabActivity and finish current, like below:
if(Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
intent.setClass(context, MyTabActivity.class);
intent.setAction(MyTabActivity.ACTION_SEARCH_PROXY);
Bundle appData = intent.getBundleExtra(SearchManager.APP_DATA);
if(appData != null) {
intent.putExtras(appData);
}
intent.putExtra(Constants.ACTIVITY_TYPE, activityType);
intent.putExtra(ActivityTabView.EXTRA_SEARCH_QUERY, query);
context.startActivity(intent);
context.finish();
}
When MyListActivity find
ActivityTabView.EXTRA_SEARCH_QUERY
it makes search query on list. And problem resolved.
Second resolved problem
Clicking "Back" button clears search query - that's ok. But clicking "Back" again shows past searches.
That's why I put noHistory to MyTabActivity:
<activity
android:name=".views.MyTabActivity"
android:noHistory="true">
</activity>
Third UNresolved problem
Now, for example, going from MyListActivityA to ItemActivityA and clicking "Back" redirects to MainActivity. I can't do back to MyTabActivity because of noHistory parameter.
Is there any good solution for using Android searching in TabActivity for each activity in tab respectively?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议阅读任务和返回堆栈。它让我对android中的活动堆栈有了更好的理解。
我的解决方案:
调用的快速搜索对话框启动调用它的活动,在本例中是 MyListActivity。这使得 TabActivity 消失,这就是为什么没有可见的 TabWidget。因此,在 MyListActivity 中实现了到 MyTabActivity 的重定向(请参阅第一个解决的问题)。 MyTabActivity 只是通过搜索查询重定向额外内容,包含在特定 MyListActivity 的意图中。
您现在所要做的就是添加一行。在启动 MyTabActivity 的意图上设置 FLAG_ACTIVITY_CLEAR_TOP 标志。
然后保留正常的活动导航。
I recommend to read Tasks and Back Stack. It gave me better understandings of activities stack in android.
My solution:
Invoked Quick Search Dialog starts the activity by which it was invoked, in this example it is MyListActivity. That makes TabActivity dissapear, that's why there is no visible TabWidget. Therefore in MyListActivity is implemented redirection to MyTabActivity (see First resolved problem). MyTabActivity just redirects extras, with search query, included in intent to specific MyListActivity.
All you have to do now is add one line. Set FLAG_ACTIVITY_CLEAR_TOP flag on intent that starts MyTabActivity.
Then normal activities navigation is preserved.