When to call activity context OR application context?

后端 未结 7 1429
野的像风
野的像风 2020-11-21 06:10

There has been a lot of posting about what these two contexts are.. But I\'m still not getting it quite right

As I understand it so far: Each is an instance of its c

7条回答
  •  终归单人心
    2020-11-21 06:15

    Two great examples of when you should use Activity context vs. the Application context are when displaying either a Toast message or a built-in Dialog message as using the Application context will cause an exception:

    ProgressDialog.show(this, ....);
    

    or

    Toast t = Toast.makeText(this,....);
    

    Both of these need information from the Activity context that is not provided in the Application context.

提交回复
热议问题