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 7420071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:10:31+00:00 2026-05-29T08:10:31+00:00

I have a long running Async Task that sends some data to my server

  • 0

I have a long running Async Task that sends some data to my server and then stops. The whole process may involve a few requests and response. I have to read data from database, send it and handle the response and update my database accordingly. I am using content providers to read and update data from database.

Now to use the Content Provider, I have to call the getContentResolver() method on context. So I am wondering whether I have to use getApplicationContext or just pass the Activity.this to my methods.

I saw a few posts like this explaining the difference between the two and in most of them they advice us to not use getApplicationContext if possible. Although I do not want my AsyncTask to lose the context from Activity.this when the Activity is destroyed or when orientation changes. So I am wondering if I can use getApplicationContext in my case or will using Activity.this fit my requirement.

  • 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-05-29T08:10:32+00:00Added an answer on May 29, 2026 at 8:10 am

    There is a reason to use each of the options.

    When you are using the context in order to modify the UI, you should use the Activity context, since in some cases using the application context might cause an exception (as described here and here). Such as in the following case:

    TextView senderNameTextView = new TextView(getApplicationContext());
    

    When you are using the context in cross-activity usage, you should not bind the Activity context to the action, since then even if the activity is destroyed, it will not be garbage-collected, as it is still referenced from the running task. In those cases, you should use the Application context. See the article in Android Developer’s site (written by Romain Guy) for even more details.

    If you are only using the context to call getContentResolver, you should use the Application context.

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

Sidebar

Related Questions

I have a long running Task that uses callbacks to feed data incrementally (rather
I have a long running process in VB6 that I want to finish before
I have a long running insert transaction that inserts data into several related tables.
I have a long-running process that must run every five minutes, but more than
i have long running task that gets called using jquery ajax. i am using
I have a long running io process that I would like to be able
I have a basic C# console application that executes a fairly long running process
If we have a long running task, we can ensure that the application doesn't
I have a long-running console-based application Sender that sends simple text to STDOUT using
I have a long running SQL statement that I want to run, and no

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.