2

Possible Duplicate:
Difference between Activity Context and Application Context

I want to know the actual difference between Application Context and Activity Context in Android..?

These two are confusing me very time. Please find me difference for this two.??

Community
  • 1
  • 1
Pratik Patel
  • 474
  • 4
  • 20

1 Answers1

8

To have a gist over the application context and activity context read below:

The application context will live as long as your application is alive and does not depend on the activities life cycle. If you plan on keeping long-lived objects that need a context, remember the application object. You can obtain it easily by calling Context.getApplicationContext() or Activity.getApplication().

In summary, to avoid context-related memory leaks, remember the following:

1.Do not keep long-lived references to a context-activity (a reference to an activity should have the same life cycle as the activity itself)

2.Try using the context-application instead of a context-activity

Reference & more Info

Arpit Garg
  • 8,476
  • 6
  • 34
  • 59
  • Isn't it exactly copied from the last paragraph from http://android-developers.blogspot.in/2009/01/avoiding-memory-leaks.html – Aritra Roy Jul 27 '15 at 06:14
  • 4
    @AritraRoy so what !!!! it helps someone, right!!!.everything is copied from here or there, but the point is ...putting it in right place to help others. Thanks for pointing the detailed link.It should be in the answer. – Nicks Aug 24 '15 at 01:22
  • Thats the point. If it exactly copied from some place, then the source should be mentioned. – Aritra Roy Aug 24 '15 at 04:34
  • 1
    @AritraRoy Thanks for suggestions and feedback , we have added the reference now. – Arpit Garg Aug 24 '15 at 05:38