Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7904067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:54:09+00:00 2026-06-03T09:54:09+00:00

Several classes in Android API require a Context parameter in their constructor, for example

  • 0

Several classes in Android API require a Context parameter in their constructor, for example ArrayAdapter, SQLiteOpenHelper or Intent. When creating such an object from inside an Activity, what context instance is more appropriate to pass to them: this (the activity instance itself) or the object returned by the activity’s getApplicationContext() method and why?

Up to now, I have used both and didn’t see any difference in the resulting functionality. Is there any rule of thumb?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:54:11+00:00Added an answer on June 3, 2026 at 9:54 am

    From the docs of getApplicationContext() method:

    Return the context of the single, global Application object of the
    current process. This generally should only be used if you need a
    Context whose lifecycle is separate from the current context, that is
    tied to the lifetime of the process rather than the current component.

    Consider for example how this interacts with {@ #registerReceiver(BroadcastReceiver, IntentFilter)}:

    • If used from an Activity context, the receiver is being registered
      within that activity. This means that you are expected to unregister
      before the activity is done being destroyed; in fact if you do not do
      so, the framework will clean up your leaked registration as it removes
      the activity and log an error. Thus, if you use the Activity context
      to register a receiver that is static (global to the process, not
      associated with an Activity instance) then that registration will be
      removed on you at whatever point the activity you used is destroyed.

    • If used from the Context returned here, the receiver is being
      registered with the global state associated with your application.
      Thus it will never be unregistered for you. This is necessary if the
      receiver is associated with static data, not a particular component.
      However using the ApplicationContext elsewhere can easily lead to
      serious leaks if you forget to unregister, unbind, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In android, I need reference context or to say pass context to several classes.
I have several classes such as Order, Customer, etc. These classes serve for holding
I have several classes, and want to work with their collections like with a
I already have a working android app with several persisted objects/classes. But what if
I have several classes like in the following example: abstract class AClass { boolean
I have several classes of vehicles such as truck, sedan, van, motorcycle. The common
I'm developing and Android App on 4.0.3 and have several ListActivities using their own
i have several classes with members called 'Id'. Originally i wanted to store these
I have several classes, that all derives from SuperClass. When the classes are created,
I have several classes each containing several methods annotated with @Test . The classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.