我在活动组中遇到了非常复杂的问题。在我的应用程序中,我使用了ActivityGroup。与我使用的其他活动导航:
Intent activityIntent = new Intent(v.getContext(), Reschedule.class);
activityIntent.putExtra("dialog_selcted_Appointment_date_time", selected_date +" "+ selected_time);
replaceContentView("activity3", activityIntent);
private void replaceContentView(String id, Intent newIntent) {
View view = this.getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) .getDecorView(); this.setContentView(view);}
我的问题是,一旦我在另一个屏幕上导航,现在这个意图如果我再进行一次相同的导航而不改变活动,那么它会给出一个错误:
02-23 18:16:15.200: E/ACRA(2433):
Caused by: android.view.WindowManager$BadTokenException: Unable to add window --
token android.app.LocalActivityManager$LocalActivityRecord@44f04458 is not valid; is your activity running?
尝试
View view = getApplicationContext().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)) .getDecorView(); this.setContentView(view);}
此外,ActivityGroup类现在已弃用。将碎片用于此目的更好、更容易。参考http://developer.android.com/guide/topics/fundamentals/fragments.html.