[問題] static vs Application

看板AndroidDev作者 (MereFantasy)時間12年前 (2013/07/17 19:33), 編輯推噓1(105)
留言6則, 2人參與, 最新討論串1/1
如果要在整個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

07/17 21:30, , 1F
我自己是用application 好處是變數設定比較集中,用static
07/17 21:30, 1F

07/17 21:31, , 2F
的話可能會比較分散,而且以前維護時可能會忘東忘西
07/17 21:31, 2F

07/17 21:32, , 3F
->後
07/17 21:32, 3F

07/18 15:34, , 4F
恩恩~ 感謝
07/18 15:34, 4F

07/18 15:34, , 5F
我發現我需要用SQLite Database 在Application中open
07/18 15:34, 5F

07/18 15:34, , 6F
就變成global database了!!! 讚
07/18 15:34, 6F
文章代碼(AID): #1Hve42h7 (AndroidDev)
文章代碼(AID): #1Hve42h7 (AndroidDev)