我收到以下错误消息:
"Activity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@417521e0 that was originally added here..."
我检查了其他stackoverflow线程,但它们都处理附加了Dialogs的活动。我没有,我只使用我的PreloadActivity
来显示一个静态(通过黑色)屏幕,同时启动另一个Activity
(它有一个黑色的淡入,所以这没关系)。我的代码如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("myapp", "PreloadActivity.onCreate");
super.onCreate(savedInstanceState);
// Set full screen mode and disable the keyguard (lockscreen)
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.preload);
}
@Override
protected void onStart() {
Log.d("myapp", "PreloadActivity.onStart");
super.onStart();
}
@Override
protected void onResume() {
Log.d("myapp", "PreloadActivity.onResume");
super.onResume();
Intent intent = new Intent(this, MyMainActivity.class);
startActivity(intent);
overridePendingTransition(0, 0); // no animation
finish();
}
这里有什么'泄露'?这有关系吗?
UPDATE :相关的logcat部分(包括堆栈跟踪)。该设备是HTC One V。
08-11 19:31:37.438: D/myapp(11724): PreloadActivity.onCreate
08-11 19:31:37.488: D/myapp(11724): PreloadActivity.onStart
08-11 19:31:37.488: D/myapp(11724): PreloadActivity.onResume
08-11 19:31:37.508: D/myapp(11724): PreloadActivity.onPause
08-11 19:31:37.708: D/myapp(11724): MyMainActivity.onCreate started
08-11 19:31:39.200: D/myapp(11724): MyMainActivity.onCreate finished, time: 1530 ms
08-11 19:31:39.200: D/myapp(11724): MyMainActivity.onStart started
08-11 19:31:39.320: D/myapp(11724): MyMainActivity.onStart finished
08-11 19:31:39.320: D/myapp(11724): MyMainActivity.onResume started
08-11 19:31:39.350: D/myapp(11724): MyMainActivity.onResume finished
08-11 19:31:39.430: D/dalvikvm(11724): GC_FOR_ALLOC freed 573K, 5% free 15070K/15779K, paused 20ms
08-11 19:31:42.153: D/myapp(11724): MyMainActivity.onPause started
08-11 19:31:42.203: I/myapp(11724): GLSurfaceView has been paused
08-11 19:31:42.243: D/myapp(11724): MyMainActivity.onPause finished
08-11 19:31:42.733: D/myapp(11724): PreloadActivity.onStop
08-11 19:31:42.753: D/myapp(11724): PreloadActivity.onDestroy
08-11 19:31:43.194: E/WindowManager(11724): Activity mypackage.PreloadActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@417521e0 that was originally added here
08-11 19:31:43.194: E/WindowManager(11724): android.view.WindowLeaked: Activity mypackage.PreloadActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@417521e0 that was originally added here
08-11 19:31:43.194: E/WindowManager(11724): at android.view.ViewRootImpl.<init>(ViewRootImpl.java:380)
08-11 19:31:43.194: E/WindowManager(11724): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:372)
08-11 19:31:43.194: E/WindowManager(11724): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:320)
08-11 19:31:43.194: E/WindowManager(11724): at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:152)
08-11 19:31:43.194: E/WindowManager(11724): at android.view.Window$LocalWindowManager.addView(Window.java:557)
08-11 19:31:43.194: E/WindowManager(11724): at android.app.Dialog.show(Dialog.java:301)
08-11 19:31:43.194: E/WindowManager(11724): at com.android.internal.policy.impl.PhoneWindow.showNavigationBarTips(PhoneWindow.java:3936)
08-11 19:31:43.194: E/WindowManager(11724): at com.android.internal.policy.impl.PhoneWindow.access$1600(PhoneWindow.java:123)
08-11 19:31:43.194: E/WindowManager(11724): at com.android.internal.policy.impl.PhoneWindow$2.run(PhoneWindow.java:3099)
08-11 19:31:43.194: E/WindowManager(11724): at android.os.Handler.handleCallback(Handler.java:608)
08-11 19:31:43.194: E/WindowManager(11724): at android.os.Handler.dispatchMessage(Handler.java:92)
08-11 19:31:43.194: E/WindowManager(11724): at android.os.Looper.loop(Looper.java:156)
08-11 19:31:43.194: E/WindowManager(11724): at android.app.ActivityThread.main(ActivityThread.java:4977)
08-11 19:31:43.194: E/WindowManager(11724): at java.lang.reflect.Method.invokeNative(Native Method)
08-11 19:31:43.194: E/WindowManager(11724): at java.lang.reflect.Method.invoke(Method.java:511)
08-11 19:31:43.194: E/WindowManager(11724): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-11 19:31:43.194: E/WindowManager(11724): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-11 19:31:43.194: E/WindowManager(11724): at dalvik.system.NativeStart.main(Native Method)
08-11 19:31:43.274: D/myapp(11724): SaveTheAdventurersActivity.onStop() started
08-11 19:31:43.304: D/myapp(11724): SaveTheAdventurersActivity.onStop() finished
答案 0 :(得分:0)
当你完成一个特定的活动实例并尝试启动一个新的活动,服务或使用该实例停止它时,就会发生这种错误,例如...
OldActivity instance;
oncreate()
{
instance=this;
}
method() {
instance.finish();
instance.startActivity(new Intent(ACTION_MAIN).setClass(instance, NewActivity.class));
}