3 回答
TA貢獻1799條經驗 獲得超8個贊
getInstance()
TA貢獻2016條經驗 獲得超9個贊
MySingleton.getInstance(Context c) {
//
// ... needing to create ...
sInstance = new MySingleton(c.getApplicationContext());}TA貢獻1859條經驗 獲得超6個贊
通常不需要子類應用程序。在大多數情況下,靜態單節點可以更模塊化的方式提供相同的功能。如果您的單例需要全局上下文(例如注冊廣播接收器),那么檢索它的函數可以在第一次構造單例時在內部使用Context.getApplicationContext()。
添加回答
舉報
