Android Trick 9: 關於Android程式中多餘的“退出”功能…

來源:互聯網
上載者:User

已經有各種文章教你如何在Android程式的任何一個頁面執行退出整個程式的功能,Android.os方法、restartPackage方法、system.exit方法,甚至有人為製造異常使程式退出的方法,令人害怕呀。

 

其實,我們在Android model的基礎上想一下,真得需要這個功能:讓使用者在任何時候,都能看到一個直接退出該應用的按鈕嗎?

我認為不需要。Google官方人員在很早就表達了這個觀點:

 

Question: Does the user have a choice to kill the application
unless we put a menu option in to kill it? If no such option exists,
how does the user terminate the application?

Answert (Romain Guy): The user doesn't, the system handles this
automatically. That's what the activity lifecycle (especially
onPause/onStop/onDestroy) is for. No matter what you do, do not put a
"quit" or "exit" application button. It is useless with Android's
application model. This is also contrary to how core applications work.

 

讓Android架構(Activity的生命週期)去自動管理應用的生死吧,目前存在的任何一個退出的方法技巧我覺得在過去或未來的某個時候都會出現錯誤和異常,而無法完成該功能。與Android架構天然相違背的東西,還是不要在menu上出現了吧。

 

參考:http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.