我的应用包含包含5个标签的tabhost,为了防止在进行其他活动时消失标签,我使用了活动组。但我无法在我的一些标签中获得至少OnCreate(),该标签在调试模式的结果中扩展了ActivityGroup。
问题出在哪里?
这是代码
tabMain.java
package com.example.myproject;
import android.app.Activity;
import android.os.Handler;
import android.widget.TextView;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.widget.TabHost;
import android.app.TabActivity;
import android.content.Intent;
import android.app.ActivityGroup;
import android.app.LocalActivityManager;
public class TpvolMainTap extends ActivityGroup {
@Override
public void onPause() {
overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
super.onPause();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tpvol_main_tap);
final TabHost tabHost = (TabHost)findViewById(R.id.tabhost);
tabHost.setup(getLocalActivityManager());
Intent intent;
TabHost.TabSpec spec;
tabHost.addTab(tabHost.newTabSpec("Tab00").setIndicator("firsttab")
.setContent(new Intent(this, TabHostNotification.class)));
//here comes to exception.(ActivityNotFoudn) I can't get at least OnCreate()
//in TabHostNotification class
intent = new Intent(this, MemberActivity.class);
spec = tabHost.newTabSpec("Tab01").setIndicator("secondtab")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent(this, VolunteerActivity.class);
spec = tabHost.newTabSpec("Tab02").setIndicator("thirdtab")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent(this, AlbumActivity.class);
spec = tabHost.newTabSpec("Tab03").setIndicator("forthtab")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent(this, EtcActivity.class);
spec = tabHost.newTabSpec("Tab04").setIndicator("fifthtab")
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
TabHostNotification.java
package com.example.tpvol;
import android.app.ActivityGroup;
import java.util.ArrayList;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class TabHostNotification extends ActivityGroup {
public static TabHostNotification notificationGroup;
private ArrayList<View> history;
@Override //exception take place before this function
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
history = new ArrayList<View>();
notificationGroup = this;
Intent intent = new Intent(this, NotificationActivity.class);
View view = getLocalActivityManager().startActivity("firttab", intent
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
replaceView(view);
}
public void replaceView(View view) {
history.add(view);
setContentView(view);
}
public void back() {
if(history.size() > 0) {
history.remove(history.size()-1);
if(history.size() == 0)
finish();
else
setContentView(history.get(history.size()-1));
}
else
{
finish();
}
}
@Override
public void onBackPressed() {
notificationGroup.back();
return ;
}
}