回击按钮3次回到主要活动 [英] Hit Back button 3 times to go back to Main Activity
问题描述
我有我可以启动搜索以搜索活动主要活动。我也可以启动我的搜索活动进行搜索。所以,我对搜索活动启动模式singleTop。
I have a main activity that I can initiate a search to searchable activity. I can also initiate a search in my search activity. So my launch mode for the searchable activity is singleTop.
如果我做我的主要活动,我可以通过单击后退按钮的一次回去从searachable活动的主要活动搜索。现在的问题是在主要活动中第一次搜索之后,如果我在我的搜索活动做一套搜索,我需要单击后退按钮三次即可返回到主要活动。我不知道我在codeS错过了。
If I do my search in main activity, I can go back to the main activity from searachable activity by clicking the back button once. Now the problem is after the first search in main activity, if I do another search in my searchable activity, I need to click the back button three times to get back to the main activity. I am not sure what I miss in my codes.
Android清单
<activity
android:name=".SearchableActivity"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
检索活动
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
getListView().setEmptyView(findViewById(R.id.lblNoResults));
db = new StoreDB(SearchableActivity.this);
onPostExecute();
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setContentView(R.layout.activity_listview);
getListView().setEmptyView(findViewById(R.id.lblNoResults));
db = new StoreDB(SearchableActivity.this);
onPostExecute();
setIntent(intent);
}
@Override
public void onDestroy() {
super.onDestroy();
db.close();
}
我在搜索活动的onDestroy。谢谢你。
I have the onDestroy in searchable activity. Thank you.
推荐答案
也许你可以检查这,我遇到同样的问题,以及最后在我发现这个解决方案意外。我不知道这是否为你工作,但你可以试试。
Maybe you can check this, I have met the same problem, and at last I found this solution accidentally. I am not sure if it work for you but you can have a try.
这篇关于回击按钮3次回到主要活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!