job.answiz.com
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

Xamarin mediaPicker.TakePhotoAsync crashes apps

I have an Xamarin.Forms app that uses XLabs, it was working fine, but suddenly it started to crash my app, if I take photo or press back button from photo screen, I was googling around for 4 hours and still have no idea why it happening, any ideas or thoughts, please help!

here is my lines of code:

    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;
        }
    }

my permission are alright:

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

stacktrace:

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]

so what happens is my MasterDetailPage recreates, because constructor of it called is calling again, but mediapicker is from another ContentPage, so I guess it 'drops' current activity and starts over, I still don't know why