getApplication() vs. getApplicationContext()

前端 未结 4 1111
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 08:39

I couldn\'t find a satisfying answer to this, so here we go: what\'s the deal with Activity/Service.getApplication() and Context.getApplicationContext()

4条回答
  •  甜味超标
    2020-11-22 09:30

    To answer the question, getApplication() returns an Application object and getApplicationContext() returns a Context object. Based on your own observations, I would assume that the Context of both are identical (i.e. behind the scenes the Application class calls the latter function to populate the Context portion of the base class or some equivalent action takes place). It shouldn't really matter which function you call if you just need a Context.

提交回复
热议问题