surfaceDestroyed什麼時候被調用

來源:互聯網
上載者:User

 

    今天看別人的代碼,突然有個疑問,surfaceDestroyed這個函數什麼時候被調用呢?


    上網搜了一番,基本都說是surface被銷毀的時候,才會調用surfaceDestroyed。問題又來了surface什麼時候被銷毀呢,大家都知道surface是surfaceview的一個專門用於畫圖的介面,所以當surfaceview的對象銷毀時,surface一定也銷毀,這時surfaceDestroyed一定會調用。


    但是,我看的那個程式明明沒有銷毀surfaceview了啊。分步調試了一下結果發現一個現象:

有兩個繼承surfaceview的類分別是 svA和svB這連個類分別定義了各自的對象AView和BView。假設現在activity設定的是AView這個對象,也就是說現在用AView的surface呢。如果這時在activity執行一下代碼:

setContentView(Bview);


這時,Aview中的surfaceDestroyed就會被調用,因為現在Bview的surface要接管Aview中的surface,Aview的surface就會銷毀,這時必然要調用A的surfaceDestroyed函數。


    在這裡只是說明一種surfaceDestroyed被調用的情況,因為個人能力有限,只能寫到自己發現的一些東西。這時第一次在論壇上寫一些東西,希望以後能堅持下去,在接受別人協助的同時來協助別人。


    最後把android協助文檔surfaceDestroyed調用條件,老外寫的簡單易懂的原文發過來。


    This is called immediately before a surface is being destroyed. After returning from this call, you should no longer try to access this surface. If you have a rendering thread that directly accesses the surface, you must
ensure that thread is no longer touching the Surface before returning from this function

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.