Difference between Activity Context and Application Context

前端 未结 7 874
耶瑟儿~
耶瑟儿~ 2020-11-22 07:51

This has me stumped, I was using this in Android 2.1-r8 SDK:

ProgressDialog.show(getApplicationContext(), ....);

and also in



        
相关标签:
7条回答
  • 2020-11-22 08:42

    I found this table super useful for deciding when to use different types of Contexts:

    1. An application CAN start an Activity from here, but it requires that a new task be created. This may fit specific use cases, but can create non-standard back stack behaviors in your application and is generally not recommended or considered good practice.
    2. This is legal, but inflation will be done with the default theme for the system on which you are running, not what’s defined in your application.
    3. Allowed if the receiver is null, which is used for obtaining the current value of a sticky broadcast, on Android 4.2 and above.

    Original article here.

    0 讨论(0)
提交回复
热议问题