8

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

animekun
  • 1,789
  • 4
  • 28
  • 45
  • 1
    Do you have any stacktrace or anything? Please define 'crash'. – Gerald Versluis Jul 02 '15 at 08:09
  • @GeraldVersluis yep, done, I guess it is not a crash, just a reload of activity – animekun Jul 02 '15 at 09:27
  • I found this other question http://stackoverflow.com/questions/26296889/xamarin-forms-take-photo-with-camera-shows-wrong-orientation-and-crashes-on-back it says something about the 'onActivityCancelled not being handled' does that help? Also, this stacktrace doesn't seem to show the actual error, there is no `Exception` in here? – Gerald Versluis Jul 02 '15 at 09:37
  • @GeraldVersluis yep, no exception – animekun Jul 02 '15 at 09:43
  • That can't be right, there *must* be an exception, else your app won't quit just like that. Could you check if you can get the output on a more detailed level in Visual Studio or Xamarin Studio? – Gerald Versluis Jul 02 '15 at 09:47
  • @GeraldVersluis I have tried a lot to catch an exception, but seems there is really no exceptions, something just drops activity, I have updated a log, all lines happens since I press "Make a photo" and until I click "OK" after making a photo, there is also a jump in memory at line 07-02 16:01:30.898, may be this made an activity to drop? – animekun Jul 02 '15 at 13:21

1 Answers1

2

TakePhotoAsync is marked obsolete (I think because of this crash). You should use GetTakePhotoUI. It starts new Intent. It works very well in my app.

Grisha
  • 713
  • 5
  • 13
  • there is no such method in xlabs.forms – animekun Jul 06 '15 at 20:17
  • 1
    Sorry, I missed that you mentioned you use Xlabs... I use [Acr.XamForms.Mobile](https://github.com/aritchie/acr-xamarin-forms). It works well. But when I've checked it today, I noticed that its author, Allan Ritchie, recently marked all this library as deprecated. He recommends to move to James Montemagno's [Xam.Plugin.Media](https://www.nuget.org/packages/Xam.Plugin.Media/) package. Probably that's the package that you (and me) should use... – Grisha Jul 07 '15 at 09:02