作者Fonger (MereFantasy)
看板AndroidDev
標題[問題] static vs Application
時間Wed Jul 17 19:33:18 2013
如果要在整個app中使用全域變數
方法有直接使用class的public static
或是使用Application,整個app只有一個instance
但是如果使用Application,就只能在Activity中使用getApplication()
但是用public static的話則到處都可以使用
那麼Application和static的使用時機為何?
--
I'm not the only one,
To crash into the sun, and live to fight another day.
Like a super nova, that old life is over.
I'm here to stay. Now I'm gonna be,
Invincible.
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.89.183
推 ncuman:我自己是用application 好處是變數設定比較集中,用static 07/17 21:30
→ ncuman:的話可能會比較分散,而且以前維護時可能會忘東忘西 07/17 21:31
→ ncuman: ->後 07/17 21:32
→ Fonger:恩恩~ 感謝 07/18 15:34
→ Fonger:我發現我需要用SQLite Database 在Application中open 07/18 15:34
→ Fonger:就變成global database了!!! 讚 07/18 15:34