我需要在我的应用程序中实现TabHost中的嵌套活动.我使用这样的ActivityGroup类:
public class CustomActivityGroup extends ActivityGroup {VIEw rootVIEw;public static CustomActivityGroup group;private ArrayList<VIEw> history;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.history = new ArrayList<VIEw>(); group = this; VIEw vIEw = getLocalActivityManager().startActivity("LoginActivity", new Intent(this,Registeractivity.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_top)) .getDecorVIEw(); replaceVIEw(vIEw);}@OverrIDeprotected voID onResume() { super.onResume(); this.history = new ArrayList<VIEw>(); group = this;}public voID replaceVIEw(VIEw v) { if (history.size() == 0) { if (rootVIEw != null) { history.add(rootVIEw); rootVIEw = null; } } history.add(v); setContentVIEw(v);}public voID back() { try { if (history.size() > 0) { history.remove(history.size() - 1); if (history.size() > 0) { setContentVIEw(history.get(history.size() - 1)); } else { finish(); } } else { finish(); } } catch (Exception ex) { }}public int getHistorySize() { return history.size();}@OverrIDepublic voID onBackpressed() { try { CustomActivityGroup.group.back(); } catch (Exception ex) { } return;}}
在我的tabactivity中:
intent = new Intent().setClass(this, CustomActivityGroup.class); spec = tabHost.newTabSpec("tab_2").setIndicator("Sign up",getResources().getDrawable(R.drawable.signup)).setContent(intent); tabHost.addTab(spec);
但当我点击相应的标签时,我得到了
FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.assignmentexpert/com.activitygroups.CustomActivityGroup}: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.assignmentexpert/com.assignmentexpert.Registeractivity}: androID.vIEw.WindowManager$BadTokenException: Unable to add window -- token androID.app.LocalActivityManager$LocalActivityRecord@405ceb00 is not valID; is your activity running? at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1651) at androID.app.ActivityThread.startActivityNow(ActivityThread.java:1491) at androID.app.LocalActivityManager.movetoState(LocalActivityManager.java:127) at androID.app.LocalActivityManager.startActivity(LocalActivityManager.java:339) at androID.Widget.TabHost$IntentContentStrategy.getContentVIEw(TabHost.java:676) at androID.Widget.TabHost.setCurrentTab(TabHost.java:348) at androID.Widget.TabHost.onTabSelectionChanged(TabHost.java:141) at androID.Widget.TabWidget$TabClickListener.onClick(TabWidget.java:456) at androID.vIEw.VIEw.performClick(VIEw.java:2485) at androID.vIEw.VIEw$PerformClick.run(VIEw.java:9080) at androID.os.Handler.handleCallback(Handler.java:587) at androID.os.Handler.dispatchMessage(Handler.java:92) at androID.os.Looper.loop(Looper.java:123) at androID.app.ActivityThread.main(ActivityThread.java:3687) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:625) at dalvik.system.NativeStart.main(Native Method)Caused by: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.assignmentexpert/com.assignmentexpert.Registeractivity}: androID.vIEw.WindowManager$BadTokenException: Unable to add window -- token androID.app.LocalActivityManager$LocalActivityRecord@405ceb00 is not valID; is your activity running? at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1651) at androID.app.ActivityThread.startActivityNow(ActivityThread.java:1491) at androID.app.LocalActivityManager.movetoState(LocalActivityManager.java:127) at androID.app.LocalActivityManager.startActivity(LocalActivityManager.java:339) at com.activitygroups.CustomActivityGroup.onCreate(CustomActivityGroup.java:31) at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1615) ... 18 more Caused by: Unable to add window -- token androID.app.LocalActivityManager$LocalActivityRecord@405ceb00 is not valID; is your activity running? at androID.vIEw.VIEwRoot.setVIEw(VIEwRoot.java:532) at androID.vIEw.WindowManagerImpl.addVIEw(WindowManagerImpl.java:177) at androID.vIEw.WindowManagerImpl.addVIEw(WindowManagerImpl.java:91) at androID.vIEw.Window$LocalWindowManager.addVIEw(Window.java:424) at androID.app.Dialog.show(Dialog.java:241) at com.asynctaskbase.AbstractTaskProgressDialogFragment.onCreateDialog(AbstractTaskProgressDialogFragment.java:68) at com.asynctaskbase.AbstractTaskProgressDialogFragment.onCreateDialog(AbstractTaskProgressDialogFragment.java:1) at androID.support.v4.app.DialogFragment.getLayoutInflater(DialogFragment.java:295) at androID.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:871) at androID.support.v4.app.FragmentManagerImpl.movetoState(FragmentManager.java:1083) at androID.support.v4.app.BackStackRecord.run(BackStackRecord.java:635) at androID.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431) at androID.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:523) at androID.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129) at androID.app.Activity.performStart(Activity.java:3791) at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1624) ... 24 more
我做错了什么?
解决方法:
我找到了这个问题的原因.我将FragmentActivitIEs添加到ActivityGroup,然后在TabHost中使用它们.当我点击调用ProgressDialog的按钮时,我得到了这个例外.我应该像这样创造它
progressDialog = new ProgressDialog(getActivity().getParent());
不是
progressDialog = new ProgressDialog(getActivity());
总结 以上是内存溢出为你收集整理的android – 用于TabActivity的BadTokenException ActivityGroup全部内容,希望文章能够帮你解决android – 用于TabActivity的BadTokenException ActivityGroup所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)