一直以为都在纳闷,为啥我的其他app崩溃次数几乎为0,而单单这个App的崩溃次数简直逆天了,我都不敢相信。
每天都有至少上千次crash。。。我也是服的
不甘心,趁着这次重构的机会,把代码好好捋了1下
Debug.WriteLine("BeginRequest " + DateTime.Now); progressRing.Visibility = Visibility.Visible; progressRing.IsActive = true; var repsonse = await HttpHelper.GetJsonAsync<USGSEarthquakesModel>(strRequestUrl); if (repsonse != null && repsonse.metadata.status == 200) { Debug.WriteLine("EndRequest " + DateTime.Now); Debug.WriteLine("BeginxBind " + DateTime.Now); Debug.WriteLine("Count " + repsonse.metadata.count); ObsList.Clear(); if (repsonse.metadata.count > 0) { foreach (FeaturesItem em in repsonse.features) { if (em.properties.mag == null) continue; try { StandardEarthquakesModel sm = new StandardEarthquakesModel { Time = Helpers.TimeConverter.Convert2MyTime(em.properties.time), Mag = (double)em.properties.mag, Latitude = (double)em.geometry.coordinates[1], Longitude = (double)em.geometry.coordinates[0], Depth = (double)em.geometry.coordinates[2], Location = em.properties.place, }; ObsList.Add(sm); } catch { } } PullToRefreshListViewControl.ItemsSource = ObsList; (Application.Current as App).gObsEarthquakeList = ObsList; TipServices.TipUpdateData((int)repsonse.metadata.count); Debug.WriteLine("EndxBind " + DateTime.Now); } else { TipServices.TipNoData(); } } else { TipServices.TipNetError(); } progressRing.Visibility = Visibility.Collapsed; progressRing.IsActive = false;
看获取json,看绑定,看数据模型,貌似都没啥问题啊。
于是就把代码分块注释掉,看看哪一部分有bug。
首先注释掉response之后代码,可以确定获取response没猫饼。
难道try catch有问题?
排除。。。
接着就是
PullToRefreshListViewControl.ItemsSource = ObsList;
有问题???
其他app也是这么写的啊。。。
注释一番后,最终确定
TipServices.TipUpdateData((int)repsonse.metadata.count);
真的有问题。
进去看看
public static void TipUpdateData(int nCount) { if (notifyPopup != null) notifyPopup.Hide(); if (strCurrentLanguage.ToLower().Equals("zh-cn")) notifyPopup = new NotifyPopup(LanguageHelper.strTipDataUpdatedAmount_zh_cn + nCount); else notifyPopup = new NotifyPopup(nCount + LanguageHelper.strTipDataUpdatedAmount_en); notifyPopup.Show(); SoundHelper.PlaySucceedTipSound(); }
这个类似安卓toast,其他app用过无数次,怎么会有bug???
那基本可以确定
SoundHelper.PlaySucceedTipSound();
这句话挂了。
private static public static void PlaySucceedTipSound() {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.Source = MediaSource.CreateFromUri(new Uri("ms-appx:///Assets/Skype.wav"));
mediaPlayer.Play();
}
把MediaPlayer拿出来设置成静态,??
最后附上App下载地址:https://www.microsoft.com/store/apps/9N3X2JZP7B96