作者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
1F:推 ncuman:我自己是用application 好处是变数设定比较集中,用static 07/17 21:30
2F:→ ncuman:的话可能会比较分散,而且以前维护时可能会忘东忘西 07/17 21:31
3F:→ ncuman: ->後 07/17 21:32
4F:→ Fonger:恩恩~ 感谢 07/18 15:34
5F:→ Fonger:我发现我需要用SQLite Database 在Application中open 07/18 15:34
6F:→ Fonger:就变成global database了!!! 赞 07/18 15:34