我在动作栏'项目上添加了一个监听器,当我点击它时,我切换到另一个活动。这有效,但当我执行此操作时,我可以注意到我在logcat上收到错误,有人可以解释我发生了什么吗?
我用这个来改变活动:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 2:
// go to activity2
Intent intent = new Intent(this, Activity2.class);
// dispose the current activity while launching the next intent
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
default:
return super.onOptionsItemSelected(item);
}
}
我的日志猫显示:
08-16 11:12:58.523: E/WindowManager(6306): Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@42bc61e8 that was originally added here
08-16 11:12:58.523: E/WindowManager(6306): android.view.WindowLeaked: Activity com.tweetmeetup.logic.main.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@42bc61e8 that was originally added here
08-16 11:12:58.523: E/WindowManager(6306): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:397)
08-16 11:12:58.523: E/WindowManager(6306): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:311)
08-16 11:12:58.523: E/WindowManager(6306): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224)
08-16 11:12:58.523: E/WindowManager(6306): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149)
08-16 11:12:58.523: E/WindowManager(6306): at android.view.Window$LocalWindowManager.addView(Window.java:556)
提前感谢。
答案 0 :(得分:3)
at android.app.Dialog.show(Dialog.java:277)
您在退出活动后尝试显示对话框。
解决方案是在退出Activity之前在您创建的Dialog上调用dismiss(),例如在onPause()中。在离开活动之前,应关闭所有窗口和对话框。
试试这个:(根据你的评论)
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 2:
// go to activity2
Intent intent = new Intent(this, Activity2.class);
// dispose the current activity while launching the next intent
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
break;
default:
return super.onOptionsItemSelected(item);
}
}