我想在Android上開發選項卡式應用程序。同時,我希望在某些選項卡上顯示搜索功能。爲此,我在清單文件中聲明瞭一些活動並將它們添加到TabHost。但問題是,當我進行搜索時,它會調用駐留在選項卡內容中的當前活動的onCreate()方法。我想要的是讓searchManager調用onNewIntent()方法,以便不創建新的活動,並且我可以處理現有活動中的搜索。我張貼我的清單,並TabActivity源文件更清晰:清單文件的搜索在TabActivity中創建新活動
部分:
<activity
android:name="KarniyarikTabsWidget"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="UrunTab"
android:theme="@android:style/Theme.NoTitleBar"
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>
<activity android:name="ArabaTab" android:theme="@android:style/Theme.NoTitleBar"
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>
<activity android:name="GecmisTab" android:theme="@android:style/Theme.NoTitleBar"
android:launchMode="singleTop">
</activity>
<activity android:name="HakkindaTab" android:theme="@android:style/Theme.NoTitleBar"
android:launchMode="singleTop">
</activity>
標籤活動onCreate方法:
public class KarniyarikTabsWidget extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("UrunTab")
.setIndicator("Ürün",res.getDrawable(R.drawable.product))
.setContent(new Intent(this, UrunTab.class));
tabHost.addTab(spec);
//Do the same for other tabs
spec = tabHost.newTabSpec("ArabaTab")
.setIndicator("Araba",res.getDrawable(R.drawable.car))
.setContent(new Intent(this, ArabaTab.class));
tabHost.addTab(spec);
//Do the same for other tabs
spec = tabHost.newTabSpec("GecmisTab")
.setIndicator("Geçmiş",res.getDrawable(R.drawable.history))
.setContent(new Intent(this, GecmisTab.class));
tabHost.addTab(spec);
//Do the same for other tabs
spec = tabHost.newTabSpec("HakkindaTab")
.setIndicator("Hakkında",res.getDrawable(R.drawable.about))
.setContent(new Intent(this, HakkindaTab.class));
tabHost.addTab(spec);
}
我認爲這兩個錯誤是相關的:http://code.google.com/p/android/issues/detail?id=17137 http://code.google.com/p/android/issues/detail? id = 4155 – Agos 2012-01-24 15:35:46
你解決了這個問題嗎? – 2012-04-12 08:48:49