我有一个使用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,所以我猜它会删除&#39;当前的活动并重新开始,我仍然不知道为什么
答案 0 :(得分:2)
TakePhotoAsync被标记为过时(我认为是因为这次崩溃)。 你应该使用GetTakePhotoUI。 它开始新的意图。它在我的应用程序中运行良好。