Android活动一直被杀死

时间:2017-03-02 17:51:17

标签: android android-activity xamarin.forms

我从其他程序员那里继承了一个应用程序的主要问题。 它有许多复杂的页面,包含来自本地数据库,谷歌地图,图像等数据的列表视图。 在运行Android 6的设备上,它或多或少都没问题。 然而,客户正在运行Android 5.1的Samsung Tab S2上对其进行测试,并且在浏览视图之间经常会崩溃。 我设法将其缩小到系统查杀并重新创建托管Xamarin Forms App的android活动。 崩溃堆栈跟踪通常指向Xamarin Forms的内部:类似

GenericAnimatorListener.n_finalize, Java.Util.Concurrent.TimeoutException: md5b60ffeb829f638581ab2bb9b1a7f4f3f.GenericAnimatorListener.finalize() timed out after 10 seconds
ViewRootImpl.checkThread, Android.Util.AndroidRuntimeException: Only the original thread that created a view hierarchy can touch its views.
ButtonRenderer.UpdateText, android.runtime.JavaProxyThrowable: System.NullReferenceException: Object reference not set to an instance of an object.
JniPeerMembers.AssertSelf, android.runtime.JavaProxyThrowable: System.ObjectDisposedException: Cannot access a disposed object.

我认为这些都是由于我在重新创建android活动后重用App对象并且Xamarin Forms对象仍在尝试使用被杀死活动的上下文而引起的。

我有什么办法可以防止重新创建活动吗?它不会发生在Android 6设备或512 MB RAM Android 5.1仿真器上。

    protected override void OnCreate(Bundle bundle)
    {
        try {
            base.OnCreate(bundle);
            //initialize xamarin forms
            Forms.Init( this, bundle );

            if (App.Instance == null) {
                LogAndroid.ForceClassInit();

                HockeyLog.LogLevel = 2;
                CrashManager.Register( this );
                MetricsManager.Register( Application );

                FormsMaps.Init( this, bundle );
                DependencyService.Register<Geolocator>();
                DependencyService.Register<MediaPicker>();
                UserDialogs.Init( () => (Activity) Forms.Context );
                new App();
            } else
                Log.Information( "Application.Instance reused" );

            LoadApplication( App.Instance );
        } catch (Exception ex) {
            Debug.WriteLine(ex.ToString());
            Log.Error(ex, "OnCreate");
            Toast.MakeText( this, "Error details saved to log", ToastLength.Short ).Show();
        }
    }

 public App()
        {
            Log.Information( "App() " + SettingsViewModel.GetVersion() + " " + OSInfo.Get() );
            instance = this;

...

典型应用程序日志

2017-03-01 12:30:05.724 -06:00 [Information] App() 1.0.72 Android 5.1.1 SM-T817V
2017-03-01 12:30:07.743 -06:00 [Information] OnResume
2017-03-01 12:30:23.479 -06:00 [Information] Menu selected MapView
2017-03-01 12:30:29.630 -06:00 [Information] Menu selected AddressListView
2017-03-01 12:30:33.474 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:30:36.051 -06:00 [Information] OnPause
2017-03-01 12:30:36.103 -06:00 [Information] OnDestroy
2017-03-01 12:30:36.243 -06:00 [Information] Application.Instance reused
2017-03-01 12:30:37.425 -06:00 [Information] OnResume
2017-03-01 12:30:37.726 -06:00 [Information] OnPause
2017-03-01 12:30:37.728 -06:00 [Information] OnDestroy
2017-03-01 12:30:37.837 -06:00 [Information] Application.Instance reused
2017-03-01 12:30:39.374 -06:00 [Information] OnResume
2017-03-01 12:30:41.192 -06:00 [Information] Pushed NewViolationView
2017-03-01 12:31:06.074 -06:00 [Information] Popped NewViolationView
2017-03-01 12:31:06.488 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:31:12.590 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:31:17.598 -06:00 [Information] Pushed modal EditStatusView
2017-03-01 12:31:23.161 -06:00 [Information] Popped modal EditStatusView
2017-03-01 12:31:26.456 -06:00 [Information] Pushed ViolationDetailView
2017-03-01 12:31:32.250 -06:00 [Information] Popped ViolationDetailView
2017-03-01 12:31:35.471 -06:00 [Information] Pushed ViolationDetailView
2017-03-01 12:31:37.237 -06:00 [Information] Popped ViolationDetailView
2017-03-01 12:31:39.415 -06:00 [Information] Pushed ViolationDetailView
2017-03-01 12:31:40.370 -06:00 [Information] Popped ViolationDetailView
2017-03-01 12:31:41.953 -06:00 [Information] Pushed modal EditStatusView
2017-03-01 12:31:45.002 -06:00 [Information] Popped modal EditStatusView
2017-03-01 12:31:48.974 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:31:51.762 -06:00 [Information] Menu selected MapView
2017-03-01 12:32:00.435 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:32:05.068 -06:00 [Information] Pushed NewViolationView
2017-03-01 12:32:07.517 -06:00 [Information] Popped NewViolationView
2017-03-01 12:32:07.872 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:32:13.364 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:32:16.759 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:32:19.459 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:32:21.671 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:32:27.835 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:32:30.248 -06:00 [Information] Pushed NewViolationView
2017-03-01 12:32:32.098 -06:00 [Information] Popped NewViolationView
2017-03-01 12:32:32.429 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:32:36.685 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:32:39.094 -06:00 [Information] Pushed modal EditStatusView
2017-03-01 12:32:42.466 -06:00 [Information] Popped modal EditStatusView
2017-03-01 12:32:46.801 -06:00 [Information] Pushed modal EditStatusView
2017-03-01 12:32:48.947 -06:00 [Information] Popped modal EditStatusView
2017-03-01 12:32:52.663 -06:00 [Information] OnPause
2017-03-01 12:32:56.292 -06:00 [Information] OnResume
2017-03-01 12:33:06.259 -06:00 [Information] Pushed EscalateViolationView
2017-03-01 12:33:08.545 -06:00 [Information] Popped EscalateViolationView
2017-03-01 12:33:08.947 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:33:12.829 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:33:15.900 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:33:19.431 -06:00 [Information] Pushed UnitDetailView
2017-03-01 12:33:45.942 -06:00 [Information] Pushed modal EditStatusView
2017-03-01 12:33:47.473 -06:00 [Information] Popped modal EditStatusView
2017-03-01 12:33:51.090 -06:00 [Information] Popped UnitDetailView
2017-03-01 12:33:57.566 -06:00 [Information] Menu selected AddressListView
2017-03-01 12:34:04.086 -06:00 [Information] Menu selected MapView
2017-03-01 12:34:29.057 -06:00 [Information] Menu selected AddressListView
2017-03-01 12:34:36.249 -06:00 [Information] Menu selected MapView
2017-03-01 12:34:44.407 -06:00 [Information] OnPause
2017-03-01 12:34:44.412 -06:00 [Information] OnDestroy
2017-03-01 12:34:44.689 -06:00 [Information] Application.Instance reused
2017-03-01 12:34:44.936 -06:00 [Information] OnResume
2017-03-01 12:34:45.116 -06:00 [Information] OnPause
2017-03-01 12:34:45.118 -06:00 [Information] OnDestroy
2017-03-01 12:34:45.189 -06:00 [Information] Application.Instance reused
2017-03-01 12:34:45.370 -06:00 [Information] OnResume
2017-03-01 12:35:14.793 -06:00 [Information] Menu selected AddressListView
2017-03-01 12:35:16.216 -06:00 [Information] OnPause
2017-03-01 12:35:16.223 -06:00 [Information] OnDestroy
2017-03-01 12:35:16.367 -06:00 [Information] Application.Instance reused
2017-03-01 12:35:16.738 -06:00 [Information] OnResume
2017-03-01 12:35:17.413 -06:00 [Information] OnPause
2017-03-01 12:35:17.415 -06:00 [Information] OnDestroy
2017-03-01 12:35:17.488 -06:00 [Information] Application.Instance reused
2017-03-01 12:35:17.891 -06:00 [Information] OnResume
2017-03-01 12:35:20.564 -06:00 [Information] Menu selected MapView

0 个答案:

没有答案