Why use ContextImpl to implement Context rather than ContextWrapper in Android?

Red Rain

Recently in the Context of two subclasses of the Context is not very understand, why use ContextImpl class to implement the Context, rather than directly using ContextWrapper?

shridutt kothari

Context is the abstract class, which acts as an interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system. It allows access to application-specific resources and classes, as well as up-calls for application-level operations such as launching activities, broadcasting and receiving intents, etc.
See Context class code here

ContextWrapper is an Adapter or proxying implementation of Context that simply delegates all of its calls to another Context. Can be subclassed to modify behavior without changing the original Context. [It uses adapter pattern]
See ContextWrapper class code here

ContextImpl is a common implementation of Context API, which provides the base context object for Activity and other application components.
See ContextImpl class code here

So if you browse through the code of above three classes, you can easily understand the abstract class Context class declares the API methods, ContextImpl implements those API methods, whereas ContextWrapper class is just an adapter of any Context type so it can be used at various places where adapter pattern is required rather than using Context child classes.

Hope it reduces confusion!!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why do some CLIs use ` and ' rather than ‛ and ’?

From Dev

Why use TimeSpan.CompareTo() rather than < > or =

From Dev

Why use a function rather than a reference to member?

From Dev

Why use ImageIcon rather than Image?

From Dev

Why to use ByteArrayInputStream rather than byte[] in Java

From Dev

Why use "nohup &" rather than "exec &"

From Dev

Why do some CLIs use ` and ' rather than ‛ and ’?

From Dev

Why use Python format rather than slicing?

From Dev

In the regularization,why we use θ^2 rather than θ?

From Dev

Why use regex finditer() rather than findall()

From Dev

XSLT - In predicate filters, why must one sometime use the XSLT current() function rather than the XPath context node dot operator?

From Dev

NFC tag - why use AAR and LaunchApp rather than URL intent with Android?

From Dev

TypeError: context must be a dict rather than Context

From Java

Angular 6 - Why use @ngrx/store rather than service injection

From Dev

Why do STL numeric algorithms use 'op' rather than 'op='?

From Dev

Why use address of first element of struct, rather than struct itself?

From Dev

Why does Clojure Spels use quoted symbols, rather than keywords?

From Java

Why do CDNs use different domain names rather than subdomains?

From Java

Why should I use a pointer rather than the object itself?

From Dev

Why does Apple use assign rather than weak to store a delegate?

From Dev

Why does `libpq` use polling rather than notification for data fetch?

From Dev

Why should we use classes rather than records, or vice versa?

From Dev

Why do Microsoft use 14.667 rather than 14 as the ControlContentThemeFontSize?

From Dev

Why do *nix folk like to use ``...'' rather than the " character?

From Dev

Why is 'use strict' usually after an IIFE (rather than at the top of a script)?

From Dev

Why does Prolog use =< Rather than <= like most languages?

From Dev

Why does Go use ^ rather than ~ for unary bitwise-not?

From Dev

Why should I use simple arrays rather than container classes?

From Dev

Why does GWT use code generators rather than annotation processors?

Related Related

  1. 1

    Why do some CLIs use ` and ' rather than ‛ and ’?

  2. 2

    Why use TimeSpan.CompareTo() rather than < > or =

  3. 3

    Why use a function rather than a reference to member?

  4. 4

    Why use ImageIcon rather than Image?

  5. 5

    Why to use ByteArrayInputStream rather than byte[] in Java

  6. 6

    Why use "nohup &" rather than "exec &"

  7. 7

    Why do some CLIs use ` and ' rather than ‛ and ’?

  8. 8

    Why use Python format rather than slicing?

  9. 9

    In the regularization,why we use θ^2 rather than θ?

  10. 10

    Why use regex finditer() rather than findall()

  11. 11

    XSLT - In predicate filters, why must one sometime use the XSLT current() function rather than the XPath context node dot operator?

  12. 12

    NFC tag - why use AAR and LaunchApp rather than URL intent with Android?

  13. 13

    TypeError: context must be a dict rather than Context

  14. 14

    Angular 6 - Why use @ngrx/store rather than service injection

  15. 15

    Why do STL numeric algorithms use 'op' rather than 'op='?

  16. 16

    Why use address of first element of struct, rather than struct itself?

  17. 17

    Why does Clojure Spels use quoted symbols, rather than keywords?

  18. 18

    Why do CDNs use different domain names rather than subdomains?

  19. 19

    Why should I use a pointer rather than the object itself?

  20. 20

    Why does Apple use assign rather than weak to store a delegate?

  21. 21

    Why does `libpq` use polling rather than notification for data fetch?

  22. 22

    Why should we use classes rather than records, or vice versa?

  23. 23

    Why do Microsoft use 14.667 rather than 14 as the ControlContentThemeFontSize?

  24. 24

    Why do *nix folk like to use ``...'' rather than the " character?

  25. 25

    Why is 'use strict' usually after an IIFE (rather than at the top of a script)?

  26. 26

    Why does Prolog use =< Rather than <= like most languages?

  27. 27

    Why does Go use ^ rather than ~ for unary bitwise-not?

  28. 28

    Why should I use simple arrays rather than container classes?

  29. 29

    Why does GWT use code generators rather than annotation processors?

HotTag

Archive