【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)_第1頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)_第2頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)_第3頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)_第4頁(yè)
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】App Launch time 101 (Android Performance Patterns Season 6 Ep. 1)_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】AppLaunchtime101(AndroidPerformancePatternsSeason6Ep.1)

Youknowwhatthistimermeans?Everyquartersecondauserspendsstaringatablankscreeninsteadofinterfacingwithyourappisaquartersecondmore.they'rewillingtocloseyourappandgivetheirattentiontosomethingelse.misunderstandingallthecomplexthingsthathappenduringyourappstartupcanleadtosomeseriousperformanceproblems.

Now,see,Androidisprettysmartwhenitcomestounderstandinghumanperformanceperception.Assoonastheuserlaunchesyourapplication,Androidwillimmediatelydisplayastartwindow,whichwillstayarounduntillyourapplicationisfully

loaded,initialized,andcandrawitsfirstframe.--你知道這個(gè)計(jì)時(shí)器是什么意思嗎?【這個(gè)不知道怎么翻譯,大概意思就是說(shuō)如果啟動(dòng)時(shí)的白屏界面時(shí)間過(guò)長(zhǎng)】。他們會(huì)希望把你的app關(guān)了,然后去做別的事情。在app啟動(dòng)過(guò)程中的那些復(fù)雜錯(cuò)誤的操作會(huì)導(dǎo)致一些嚴(yán)重的性能問(wèn)題。

現(xiàn)在我們了解了,android其實(shí)是很聰明的,它能夠明白人類對(duì)性能的感知。一旦用戶點(diǎn)擊桌面圖標(biāo),android會(huì)立即展示啟動(dòng)窗口,這個(gè)窗口將持續(xù),直到你的應(yīng)用完全加載,初始化,繪制首幀。

Thisbehaviorismostoftenseenwhenyourappisbootedforthefirsttime,butitcaneasilyhappenothertimesaswell,likewhentheactivityisbroughttotheforeground,oraftertheuserbacksoutofyourapp,oraftersomeportionofyourapphasbeenpurgedbythesystemtosavememory.Basically,anytimetheusermovesfromsomethingelsetoyourapplication,there'sachanceyoucanseethistypeofbehavior.--這種情況在在app冷啟動(dòng)時(shí)候很常見(jiàn),但是也很容易發(fā)生在其他時(shí)候,比如活動(dòng)被置于前臺(tái),或者用于退出你的app,或者你的app的某些部分被系統(tǒng)清楚用于節(jié)省內(nèi)存。基本上,任何時(shí)候,用戶向你的應(yīng)用轉(zhuǎn)移一些東西(應(yīng)該是指調(diào)用你的app),你也有機(jī)會(huì)看到這種情況。****套用知乎:coldstart:應(yīng)用第一次啟動(dòng)。

warmstart:

Theimportantpointhereisthis.Lettingtheuserspendtoomuchtimelookingatthestartwindowgivesthenampleopportunitytogetboredandmoveontootherthings.AndtakingtoolongingeneralcouldevencausetheApplicationNotRespondingdialogtopop

up.Neitheroftheseareverygoodforuserretention.--真正重要的點(diǎn)是這個(gè)。讓用戶花太長(zhǎng)時(shí)間在啟動(dòng)界面,會(huì)讓他們感到很枯燥,然后轉(zhuǎn)去做別的事情。并且花太長(zhǎng)的時(shí)間在這上面,甚至?xí)?dǎo)致應(yīng)用彈出無(wú)響應(yīng)彈窗(NAR)。這些對(duì)于挽留用戶都是沒(méi)有好處的。

Sofromthetechnicalside,thewholeprocessworkssomethinglikethis.whentheuserlaunchesyourapp,thesystemdoesabitofworktoloadyourapplicationinformationandcreateauniqueprocessforyourapp.--所以,從技術(shù)方面,全部的進(jìn)程工作情況,就如圖下圖。當(dāng)用戶啟動(dòng)你的app,系統(tǒng)會(huì)做一點(diǎn)小工作,加載你的應(yīng)用信息,給你的app創(chuàng)建一個(gè)獨(dú)立的進(jìn)程。

Fromthere,thesystemwilldisplaythestratingwindowandbasicallyhangoutuntiltheapplicationisupandrunning.--從那以后,系統(tǒng)會(huì)顯示啟動(dòng)界面并且會(huì)持續(xù)到應(yīng)用啟動(dòng)和運(yùn)行。

Meanwhile,theapplicationprocesswillcreatetheapplicationobjectandlaunchthemainthread.--同時(shí),應(yīng)用進(jìn)程會(huì)創(chuàng)建應(yīng)用對(duì)象,啟動(dòng)主線程。

Thisiswhereyourstartupactivitywillbeinitalized,created,inflated,andfinallydrawn.--主線程完成activity的初始化,創(chuàng)建,膨脹,繪制。

it'sonlyatthispoint,aftertheapplicationhasdrawnitsfirstframe,thatthesystemprocessthengoesandswapsoutthestartwindowfortheapplication.--在這點(diǎn)上,當(dāng)應(yīng)用繪制了首幀之后,系統(tǒng)進(jìn)程會(huì)把啟動(dòng)窗口替換成app的顯示窗口。

Now,tobeclear,themajorityofthatentireprocesshappensprettycleanly.There'snotreallymuchchancethatperformancecangoofftherails.However,therearethreebigareaswherethingscouldbecomeproblematicthatyoushouldkeepaneyeon.--現(xiàn)在很清楚了,大多數(shù)的進(jìn)程產(chǎn)生的很干凈(大概這個(gè)意思吧)。性能出差錯(cuò)的可能性也很小。但是還是有三個(gè)大的方面會(huì)造成問(wèn)題,需要你自己關(guān)注。

Thefirstthingyoushouldreallytakealookatisalltheworkthatgoesintocreatingyouractivityclass.Mostoften,there'slotsofheavyliftingthatoccursduringthisprocess,butheaviesthastobetheinflationoflayoutsandloadingofresourcesthatgoesalongwithit.Thisisnotacheapprocess,andifyourlayoutsaretoocomplexoryou'vegotsomeblockinglogicinthere,thiscancausesomereallybigproblems.--第一件你需要真正關(guān)注的事情就是,所有的工作都會(huì)先創(chuàng)建你的activity類。最經(jīng)常的,大量繁重任務(wù)發(fā)生在這個(gè)進(jìn)程期間。但是最繁重的還是inflation布局和加載資源。這不是一個(gè)廉價(jià)的進(jìn)程,如果你的布局太復(fù)雜,或者是你在這里產(chǎn)生了一些閉鎖邏輯,那就會(huì)造成×××煩。

Onasimilarnote,makesureyoutakealookatapplicationinitialization.Forreallycomplexapps,theinitializationoftheappobjectoftenbecomesajunkdrawerforlotsofglobalclassesthatmightbeusedbetweenactivities.Sotheretendstobelotsofworkherethatcouldbedeferredtolatertimesorperhapslodedinalazy-loadfashion.--同樣的,確定你關(guān)注了應(yīng)用的初始化,對(duì)于復(fù)雜的app,app對(duì)象的初始化經(jīng)常會(huì)成為一個(gè)大量全局類的一個(gè)垃圾抽屜,可能會(huì)被用在活動(dòng)中(翻譯的越來(lái)越不行了)。所以這里會(huì)有很多工作可能會(huì)被推遲,或者是在lazy-load模式下加載。

Nowthere'slotsofapplicationsouttherewhichprovidecustomstartwindows.Thisiseitherdonetohelpbrandtheapplicationortomakeaslowloadlooklikeacustom-brandedapplication.Nowifyou'redoingthistohidebadloadtimes,obcviously,youshouldfixthatfirst.Butifyou'redoingitforbranding,thenyouneedtobeawarethatthere'sarightandawrongwaytosetthisup,sothatitdoes'ntinfluencetheuserperceptiontoonegatively.--現(xiàn)在,很多的應(yīng)用都會(huì)提供啟動(dòng)窗口?;蛘邘椭故緫?yīng)用品牌,或者降慢應(yīng)用加載。既然你做這個(gè)就是為了隱藏不好的加載時(shí)間,那么你就應(yīng)該修復(fù)他。但是如果你設(shè)置品牌,那你就應(yīng)該注意到設(shè)置這個(gè)的正確和錯(cuò)誤的方式。以便不會(huì)讓用戶感覺(jué)到太消極。

Butbeforeyourunoffintotheweedsandtrytofixthesetypesofcommonpatterns,youneedtositdownandfigureoutifyouhaveaprobleminthefirstplace.Thankfully,Androidhasafewtoolstohelp.--在解決問(wèn)題之前,如果你在第一個(gè)位置有問(wèn)題,你需要坐下來(lái),找出它。感謝android有這些工具來(lái)幫助我們。

Firstlyisdisplaytime.ForreleasesafterKitKat,Logcatwillincludeanoutputlinewhichdisplaystheamountoftimebetweenwhentheprocesswaslaunchedandtheactivityfinallydrawntothescreen.Thiscanbehelpful,becauseitgivesyouageneralideahowlongit

takestooccurforyourapplication.--首先是顯示時(shí)間。在KitKat(Android4.4)版本之后,日志將會(huì)包含輸出行,它將顯示在從程序啟動(dòng)到activity最后繪制在屏幕這段總的時(shí)間。這是很有幫助的,對(duì)于你的應(yīng)用啟動(dòng)的時(shí)間,他會(huì)給出一個(gè)大體的建議。

oh,bytheway,notifyouwanttoseethisvalueinisdeofAndroidStudio,youneedtoturnofffiltersfortheLogcatoutput.

Sokeepthatinmind.--噢,記住,如果你不想在AndroidStudio看到這些值,你需要在日志輸出上關(guān)掉過(guò)濾功能。

SecondlyisreportFullyDrawnfunction.Thedisplayedmetricthat'srepotedinLogcatisusefulformostsituationswhereyou'dliketotrackdownthetimeittakestogofromapplicationstarttofirstviseble.Howere,inmodernapplicationdevelopment,there'softenagreatdealoflazyloading-thatis,ratherthanblockingtheinitialdrawingofthewindow,asynchronouslyloadingresourcesandviewsinthebackgroundandupdatingtheviewhierachyaccordingly.Theresultisthatwhiletheinitialactivitymaybevisible,itmaynotyetbefullyloadedwithrespecttoresources,whichcouldbeconsideredaseparatemetrictousewhenevaluatinglaunchtimeperformance.--其次是reportFullyDrawn方法:我們通常來(lái)說(shuō)會(huì)使用異步懶加載的方式來(lái)提升程序畫面的顯示速度,這通常會(huì)導(dǎo)致的一個(gè)問(wèn)題是,程序畫面已經(jīng)顯示,可是內(nèi)容卻還在加載中。為了衡量這些異步加載資源所耗費(fèi)的時(shí)間,我們可以在異步加載完畢之后調(diào)用activity.reportFullyDrawn()方法來(lái)告訴系統(tǒng)此時(shí)的狀態(tài),以便獲取整個(gè)加載的耗時(shí)。

Toaddressthisconcern,youcanmanuallycalltheactivity.reportFullyDrawnfunctiontoletthesystemknowthatyouractivityisfinishedwithitslazyloading.

Thirdismethodtracing.Whiledisplaytimean

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論