0

在我的 monodroid 应用程序中,我有一个用户可以旋转它的活动。当我多次背靠背旋转它时,会导致此错误:

 12-17 11:58:40.367: E/WindowManager(2115): Activity myapp.myActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405bc398 that was originally added here
12-17 11:58:40.367: E/WindowManager(2115): android.view.WindowLeaked: Activity myapp.myActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@405bc398 that was originally added here
12-17 11:58:40.367: E/WindowManager(2115):  at android.view.ViewRoot.<init>(ViewRoot.java:275)
12-17 11:58:40.367: E/WindowManager(2115):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
12-17 11:58:40.367: E/WindowManager(2115):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
12-17 11:58:40.367: E/WindowManager(2115):  at android.view.Window$LocalWindowManager.addView(Window.java:430)
12-17 11:58:40.367: E/WindowManager(2115):  at android.app.Dialog.show(Dialog.java:288)
12-17 11:58:40.367: E/WindowManager(2115):  at myapp.myActivity.n_onCreate(Native Method)
12-17 11:58:40.367: E/WindowManager(2115):  at myapp.myActivity.onCreate(PropertyShowActivity.java:77)
12-17 11:58:40.367: E/WindowManager(2115):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
12-17 11:58:40.367: E/WindowManager(2115):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)
12-17 11:58:40.367: E/WindowManager(2115):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
12-17 11:58:40.367: E/WindowManager(2115):  at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3242)
12-17 11:58:40.367: E/WindowManager(2115):  at android.app.ActivityThread.access$1600(ActivityThread.java:132)
12-17 11:58:40.367: E/WindowManager(2115):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1037)
12-17 11:58:40.367: E/WindowManager(2115):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-17 11:58:40.367: E/WindowManager(2115):  at android.os.Looper.loop(Looper.java:143)
12-17 11:58:40.367: E/WindowManager(2115):  at android.app.ActivityThread.main(ActivityThread.java:4196)
12-17 11:58:40.367: E/WindowManager(2115):  at java.lang.reflect.Method.invokeNative(Native Method)
12-17 11:58:40.367: E/WindowManager(2115):  at java.lang.reflect.Method.invoke(Method.java:507)
12-17 11:58:40.367: E/WindowManager(2115):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
12-17 11:58:40.367: E/WindowManager(2115):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
12-17 11:58:40.367: E/WindowManager(2115):  at dalvik.system.NativeStart.main(Native Method)
12-17 11:58:40.377: W/MapActivity(2115): Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@40626398

我不知道这是为了什么。有谁能够帮助我?

在上述错误之前我也有这个信息:

Recycling dispatcher android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher@40626398

回收地图对象。将目标 GC 堆从 33.796MB 限制到 32.000MB 395280 字节的外部分配对于此进程来说太大。VM 不允许我们将 395280 字节的 Clamp 目标 GC 堆从 33.789MB 分配到 32.000MB

我的活动中有一些使用通用图像加载器加载的图像是因为它们吗?如果它是真的我怎么能解决这个问题?

4

3 回答 3

0

您可能在某处创建了内存泄漏。检查您是否没有存储对 Gui 对象的引用。

于 2012-12-17T08:56:31.713 回答
0

您似乎在 OnCreate() 方法中创建了一个 Dialog(或从 Dialog 派生的类)。Dialog 使用泄漏的内部类 PhoneWindow。旋转设备时,活动会贯穿整个生命周期,您应该在那里清理对话框。建议的地方是 OnPause() 方法:

protected override void OnPause()
{
   base.OnPause();

   if (this.dlg != null)
      this.dlg.Dismiss();
}

活动生命周期在此处描述: https ://developer.android.com/reference/android/app/Activity.html

于 2012-12-17T09:27:12.970 回答
0

如果您不更改布局或需要重新配置/重新加载控件或布局,您可能需要考虑添加如下属性更改:

[Activity(Label = "MyActivity", Icon = "@drawable/MyActivity", Theme = "@style/AppTheme"
                , ConfigurationChanges = Android.Content.PM.ConfigChanges.Orientation)]

Android.Content.PM.ConfigChanges.Orientation属性通知Activity任何方向更改都需要手动处理。因此,如果您只是希望视图在不重新启动活动的情况下旋转,那么进行该属性更改应该可以解决您的问题。

如果您需要更改布局或需要对方向更改采取操作,则需要覆盖OnConfigurationChanged方法。

可以在Xamarin 文档站点上找到有关此过程的更多信息。查看“防止活动重启”部分。

于 2012-12-17T15:11:48.350 回答