8

我有一个使用 XLabs 的 Xamarin.Forms 应用程序,它工作正常,但突然它开始让我的应用程序崩溃,如果我从照片屏幕拍照或按返回按钮,我在谷歌上搜索了 4 个小时,仍然不知道为什么它发生了,任何想法或想法,请帮助!

这是我的代码行:

    private async Task TakePicture()
    {
        mediaPicker = Resolver.Resolve<IDevice>().MediaPicker;

        try
        {
            var mediaFile = await mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions
            {
                DefaultCamera = CameraDevice.Front,
                MaxPixelDimension = 1,
                PercentQuality = 2,
            });

            var image = GetResizedImage(mediaFile.Source, 990, 560);
            OnImageUpdate(this, image);
        }
        catch (Exception ex)
        {
            this.status = ex.Message;
        }
    }

我的许可没问题:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

堆栈跟踪:

07-02 16:01:20.433 D/Mono    (20722): Assembly Ref addref XLabs.Platform.Droid[0x77114be8] -> System[0x7915c498]: 14
07-02 16:01:20.463 D/Activity(20722): #1 setTransGradationModeColor false
07-02 16:01:21.118 D/Mono    (20722): Assembly Ref addref Xamarin.Forms.Platform.Android[0x7710d050] -> System.Xml[0x77bdfb08]: 6
07-02 16:01:21.143 D/Mono    (20722): Assembly Ref addref System.Runtime.Serialization[0x7b249010] -> System[0x7915c498]: 15
07-02 16:01:21.223 D/Mono    (20722): Assembly Ref addref System.Runtime.Serialization[0x7b249010] -> System.Core[0x77910b48]: 13
07-02 16:01:21.393 D/AbsListView(20722): onDetachedFromWindow
07-02 16:01:21.413 D/AbsListView(20722): onDetachedFromWindow
07-02 16:01:21.978 D/LocationHandler(20722): logged location changed: Location[fused 55.545249,37.561894 acc=10 et=+3d2h50m24s315ms]
07-02 16:01:26.948 D/LocationHandler(20722): logged location changed: Location[fused 55.545247,37.561896 acc=10 et=+3d2h50m29s329ms]
07-02 16:01:30.343 D/Activity(20722): #1 setTransGradationModeColor false
07-02 16:01:30.503 I/dalvikvm-heap(20722): Grow heap (frag case) to 70.455MB for 47775760-byte allocation
07-02 16:01:30.528 D/dalvikvm(20722): GC_CONCURRENT freed 11651K, 22% free 59395K/75312K, paused 1ms+2ms, total 26ms
07-02 16:01:30.898 D/dalvikvm(20722): GC_EXPLICIT freed 7037K, 28% free 54531K/75312K, paused 1ms+3ms, total 21ms
07-02 16:01:30.908 D/Mono    (20722): GC_OLD_BRIDGE num-objects 532 num_hash_entries 585 sccs size 580 init 0.00ms df1 1.07ms sort 0.20ms dfs2 0.67ms setup-cb 0.58ms free-data 0.92ms links 66/66/60/2 dfs passes 1183/646
07-02 16:01:30.908 D/Mono    (20722): GC_MAJOR: (LOS overflow) pause 19.10ms, total 19.27ms, bridge 39.09ms major 2240K/2096K los 3281K/17532K
07-02 16:01:30.943 E/MoreInfoHPW_View(20722): Parent view is not a TextView
07-02 16:01:30.983 D/ProgressBar(20722): updateDrawableBounds: left = 0
07-02 16:01:30.983 D/ProgressBar(20722): updateDrawableBounds: top = 0
07-02 16:01:30.983 D/ProgressBar(20722): updateDrawableBounds: right = -2
07-02 16:01:30.983 D/ProgressBar(20722): updateDrawableBounds: bottom = -2
07-02 16:01:30.993 D/ProgressBar(20722): updateDrawableBounds: left = 0
07-02 16:01:30.993 D/ProgressBar(20722): updateDrawableBounds: top = 0
07-02 16:01:30.993 D/ProgressBar(20722): updateDrawableBounds: right = -2
07-02 16:01:30.993 D/ProgressBar(20722): updateDrawableBounds: bottom = -2
07-02 16:01:31.003 D/Activity(20722): #3 setTransGradationModeColor to false
07-02 16:01:31.043 D/ProgressBar(20722): updateDrawableBounds: left = 0
07-02 16:01:31.043 D/ProgressBar(20722): updateDrawableBounds: top = 0
07-02 16:01:31.043 D/ProgressBar(20722): updateDrawableBounds: right = 96
07-02 16:01:31.043 D/ProgressBar(20722): updateDrawableBounds: bottom = 96
07-02 16:01:31.048 W/View    (20722): requestLayout() improperly called by  md5530bd51e982e6e7b340b73e88efe666e.PageRenderer{42886ae8 V.E...C. ......ID 0,0-720,1134} during layout: running second layout pass
07-02 16:01:31.048 W/View    (20722): requestLayout() improperly called by md5530bd51e982e6e7b340b73e88efe666e.ActivityIndicatorRenderer{4279fa78 V.E..... ......ID 0,0--2,-2} during layout: running second layout pass
07-02 16:01:31.048 W/View    (20722): requestLayout() improperly called by md5530bd51e982e6e7b340b73e88efe666e.RendererFactory_DefaultRenderer{4270c278 V.E...C. ......ID 0,0--2,-2} during layout: running second layout pass
07-02 16:01:32.003 D/LocationHandler(20722): logged location changed: Location[fused 55.545246,37.561896 acc=10 et=+3d2h50m34s361ms]

所以会发生什么是我的 MasterDetailPage 重新创建,因为它调用的构造函数再次调用,但 mediapicker 来自另一个 ContentPage,所以我猜它“丢弃”当前活动并重新开始,我仍然不知道为什么

4

1 回答 1

2

TakePhotoAsync 被标记为过时(我认为是因为这次崩溃)。您应该使用 GetTakePhotoUI。它开始了新的意图。它在我的应用程序中运行良好。

于 2015-07-03T11:48:30.910 回答