App Center Crashes for Android - Visual Studio - Microsoft Docs
文章推薦指數: 80 %
Collecting crashes works for both beta and live apps, i.e. those submitted to Google Play. Crash logs contain valuable information for you ...
Skiptomaincontent
Thisbrowserisnolongersupported.
UpgradetoMicrosoftEdgetotakeadvantageofthelatestfeatures,securityupdates,andtechnicalsupport.
DownloadMicrosoftEdge
Moreinfo
Tableofcontents
Exitfocusmode
Language
ReadinEnglish
Save
Tableofcontents
ReadinEnglish
Save
Feedback
Edit
Twitter
LinkedIn
Facebook
Email
Tableofcontents
AppCenterCrashes(Android)
Article
03/23/2021
10minutestoread
20contributors
Isthispagehelpful?
Yes
No
Anyadditionalfeedback?
FeedbackwillbesenttoMicrosoft:Bypressingthesubmitbutton,yourfeedbackwillbeusedtoimproveMicrosoftproductsandservices.Privacypolicy.
Submit
Thankyou.
Inthisarticle
Android
iOS
ReactNative
Xamarin
UWP
WPF/WinForms
Unity
macOS
tvOS
Cordova
AppCenterCrasheswillautomaticallygenerateacrashlogeverytimeyourappcrashes.Thelogisfirstwrittentothedevice'sstorageandwhentheuserstartstheappagain,thecrashreportwillbesenttoAppCenter.Collectingcrashesworksforbothbetaandliveapps,i.e.thosesubmittedtoGooglePlay.Crashlogscontainvaluableinformationforyoutohelpfixthecrash.
FollowtheGettingStartedsectionifyouhaven'tsetuptheSDKinyourapplicationyet.
Generateatestcrash
AppCenterCrashesprovidesyouwithanAPItogenerateatestcrashforeasytestingoftheSDK.ThisAPIcanonlybeusedindebugbuildsandwon'tdoanythinginreleasebuilds.
Crashes.generateTestCrash();
Crashes.generateTestCrash()
Getmoreinformationaboutapreviouscrash
AppCenterCrasheshastwoAPIsthatgiveyoumoreinformationincaseyourapphascrashed.
Didtheappreceivealowmemorywarningintheprevioussession?
AtanytimeafterstartingtheSDK,youcancheckiftheappreceivedamemorywarningintheprevioussession:
Crashes.hasReceivedMemoryWarningInLastSession();
Crashes.hasReceivedMemoryWarningInLastSession()
ThisAPIisasynchronous,youcanreadmoreaboutthatinourAppCenterAsynchronousAPIsguide.
Note
ThismethodmustonlybeusedafterCrasheshasbeenstarted,itwillalwaysreturnfalsebeforestart.
Note
Insomecases,adevicewithlowmemorycan'tsendevents.
Didtheappcrashintheprevioussession?
AtanytimeafterstartingtheSDK,youcancheckiftheappcrashedinthepreviouslaunch:
Crashes.hasCrashedInLastSession();
Crashes.hasCrashedInLastSession()
ThisAPIisasynchronous,youcanreadmoreaboutthatinourAppCenterAsynchronousAPIsguide.
ThiscomesinhandyincaseyouwanttoadjustthebehaviororUIofyourappafteracrashhasoccurred.SomedeveloperschosetoshowadditionalUItoapologizetotheirusers,orwantwaytogetintouchafteracrashhasoccurred.
Note
ThismethodmustonlybeusedafterCrasheshasbeenstarted,itwillalwaysreturnfalsebeforestart.
Detailsaboutthelastcrash
Ifyourappcrashedpreviously,youcangetdetailsaboutthelastcrash.
Crashes.getLastSessionCrashReport();
Crashes.getLastSessionCrashReport()
ThisAPIisasynchronous,youcanreadmoreaboutthatinourAppCenterAsynchronousAPIsguide.
TherearenumeroususecasesforthisAPI,themostcommononeispeoplewhocallthisAPIandimplementtheircustomCrashesListener.
Note
ThismethodmustonlybeusedafterCrasheshasbeenstarted,itwillalwaysreturnnullbeforestart.
CustomizeyourusageofAppCenterCrashes
AppCenterCrashesprovidescallbacksfordeveloperstoperformadditionalactionsbeforeandwhensendingcrashlogstoAppCenter.
Tohandlethecallbacks,eitherimplementallmethodsintheCrashesListenerinterface,oroverridetheAbstractCrashesListenerclassandpickonlytheonesyou'reinterestedin.
UseyourownCrashesListener
CreateyourownCrashesListenerandassignitlikethis:
CrashesListenercustomListener=newCrashesListener(){
//Implementallcallbackshere.
};
Crashes.setListener(customListener);
valcustomListener=object:CrashesListener{
//Implementallcallbackshere.
}
Crashes.setListener(customListener)
Incaseyou'reonlyinterestedincustomizingsomeofthecallbacks,usetheAbstractCrashesListenerinstead:
AbstractCrashesListenercustomListener=newAbstractCrashesListener(){
//Implementanycallbackhereasrequired.
};
Crashes.setListener(customListener);
valcustomListener=object:AbstractCrashesListener(){
//Implementanycallbackhereasrequired.
}
Crashes.setListener(customListener)
Note
SetthelistenerbeforecallingAppCenter.start(),sinceAppCenterstartsprocessingcrashesimmediatelyafterthestart.
Shouldthecrashbeprocessed?
Implementthiscallbackifyouwanttodecideifaparticularcrashneedstobeprocessedornot.Forexample,therecouldbeasystemlevelcrashthatyou'dwanttoignoreandthatyoudon'twanttosendtoAppCenter.
@Override
publicbooleanshouldProcess(ErrorReportreport){
returntrue;//returntrueifthecrashreportshouldbeprocessed,otherwisefalse.
}
overridefunshouldProcess(report:ErrorReport?):Boolean{
returntrue
}
Askfortheuser'sconsenttosendacrashlog
Ifuserprivacyisimportanttoyou,youmightwanttogetuserconfirmationbeforesendingacrashreporttoAppCenter.TheSDKexposesacallbackthattellsAppCenterCrashestoawaituserconfirmationbeforesendinganycrashreports.
Ifyouchosetodoso,you'reresponsibleforobtainingtheuser'sconfirmation,e.g.throughadialogpromptwithoneofthefollowingoptions:AlwaysSend,Send,andDon'tsend.Basedontheinput,you'lltellAppCenterCrasheswhattodoandthecrashwillthenbehandledaccordingly.
Note
TheSDKdoesn'tdisplayadialogforthis,theappmustprovideitsownUItoaskforuserconsent.
ThefollowingcallbackshowshowtotelltheSDKtowaitforuserconfirmationbeforesendingcrashes:
@Override
publicbooleanshouldAwaitUserConfirmation(){
//BuildyourownUItoaskforuserconsenthere.SDKdoesn'tprovideonebydefault.
//ReturntrueifyoubuiltaUIforuserconsentandarewaitingforuserinputonthatcustomUI,otherwisefalse.
returntrue;
}
overridefunshouldAwaitUserConfirmation():Boolean{
returntrue
}
Ifyoureturntrue,yourappmustobtain(usingyourowncode)theuser'spermissionandmessagetheSDKwiththeresultusingthefollowingAPI:
//Dependingontheuser'schoice,callCrashes.notifyUserConfirmation()withtherightvalue.
Crashes.notifyUserConfirmation(Crashes.DONT_SEND);
Crashes.notifyUserConfirmation(Crashes.SEND);
Crashes.notifyUserConfirmation(Crashes.ALWAYS_SEND);
Crashes.notifyUserConfirmation(Crashes.DONT_SEND)
Crashes.notifyUserConfirmation(Crashes.SEND)
Crashes.notifyUserConfirmation(Crashes.ALWAYS_SEND)
Asanexampleyoucanrefertoourcustomdialogexample.
Getinformationaboutthesendingstatusforacrashlog
Attimes,youwanttoknowthestatusofyourappcrash.AcommonusecaseisthatyoumightwanttoshowUIthattellstheusersthatyourappissubmittingacrashreport,or,incaseyourappiscrashingquicklyafterthelaunch,youwanttoadjustthebehavioroftheapptomakesurethecrashlogscanbesubmitted.AppCenterCrasheshasthreedifferentcallbacksthatyoucanuseinyourapptobenotifiedofwhat'sgoingon:
ThefollowingcallbackwillbeinvokedbeforetheSDKsendsacrashlog
@Override
publicvoidonBeforeSending(ErrorReporterrorReport){
//Yourcode,e.g.topresentacustomUI.
}
overridefunonBeforeSending(report:ErrorReport?){
//Yourcode,e.g.topresentacustomUI.
}
Incasewehavenetworkissuesoranoutageontheendpoint,andyourestarttheapp,onBeforeSendingistriggeredagainafterprocessrestart.
ThefollowingcallbackwillbeinvokedaftertheSDKsentacrashlogsuccessfully
@Override
publicvoidonSendingSucceeded(ErrorReportreport){
//Yourcode,e.g.tohidethecustomUI.
}
overridefunonSendingSucceeded(report:ErrorReport?){
//Yourcode,e.g.tohidethecustomUI.
}
ThefollowingcallbackwillbeinvokediftheSDKfailedtosendacrashlog
@Override
publicvoidonSendingFailed(ErrorReportreport,Exceptione){
//Yourcodegoeshere.
}
overridefunonSendingFailed(report:ErrorReport?,e:Exception?){
//Yourcodegoeshere.
}
ReceivingonSendingFailedmeansanon-recoverableerrorsuchasa4xxcodeoccurred.Forexample,401meanstheappSecretiswrong.
Thiscallbackisn'ttriggeredifit'sanetworkissue.Inthiscase,theSDKkeepsretrying(andalsopausesretrieswhilethenetworkconnectionisdown).
Addattachmentstoacrashreport
Youcanaddbinaryandtextattachmentstoacrashreport.TheSDKwillsendthemalongwiththecrashsothatyoucanseetheminAppCenterportal.Thefollowingcallbackwillbeinvokedrightbeforesendingthestoredcrashfrompreviousapplicationlaunches.Itwon'tbeinvokedwhenthecrashhappens.Besuretheattachmentfileisn'tnamedminidump.dmpasthatnameisreservedforminidumpfiles.Here'sanexampleofhowtoattachtextandanimagetoacrash:
@Override
publicIterable
延伸文章資訊
- 1Google Play Console Crash Report - Unity Answers
Google Play Console Crash Report. This is one of my Unity 3D Game Projects publish on Google Play...
- 2查看當機與應用程式無回應(ANR) 錯誤的資料 - Google Support
如果您的應用程式發生當機與應用程式無回應(ANR) 錯誤,您可以使用Play 管理中心查看相關資料。這些資料來自於使用者選擇自動分享使用狀況與診斷資料的Android 裝置。
- 3App Center Crashes for Android - Visual Studio - Microsoft Docs
Collecting crashes works for both beta and live apps, i.e. those submitted to Google Play. Crash ...
- 4Google Play Developer Reporting API
Use the Google Play Developer Reporting API to collect data about your app's quality from Android...
- 5When an app crashes there is a report button. Where does this ...
When an app installed from the Google Play store crashes, and the user consents to reporting the ...