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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:10:04+00:00 2026-06-16T06:10:04+00:00

I have android app with asynchrounous data sync from server via pressing button. However

  • 0

I have android app with asynchrounous data sync from server via pressing button. However I need the button to be in all activities of app so I decided to have updateTask as standalone class.

In updateTask I download some xml data. Then use bussines object to process it and finaly let this bussines object to handle saving (or updating) to android db.

Based on ORMLite tutorials I should get databaseHelper by calling OpenHelperManager.getHelper(context, DatabaseHelper.class). My problem is that I need some context for OpenHelperManager which I currently don’t have.

I think that best way is pass activity’s context to updateTask but how do I do it? Also isn’t it weird to pass context further to bussines object which has nothing to do with any activity. And finally: what even is the context? Does it simply stand for activity parent or it has some deeper purpose?

Thanks 🙂

  • 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-16T06:10:05+00:00Added an answer on June 16, 2026 at 6:10 am

    Here’s a couple ways of doing it. I’m pretty sure all 3 should work, but I haven’t tested them myself.

    Method 1

    Create a constructor for the AsyncTask that takes in the Context and store it so you can use it when it’s executing.

    AsyncTask code

    public class DataProcessor extends AsyncTask<Void, Void, Void>{
    
        private Context mContext;
    
        public DataProcessor(Context context){
            this.mContext = context;
        }
    
        @Override
        protected Void doInBackground(Void... params) {
            DataBaseHelper helper = OpenHelperManager.getHelper(mContext, DatabaseHelper.class)
            // Your code here
        }
    }
    

    Implementation code (for an Activity)

    new DataProcessor(this).execute();
    

    Method 2

    Pass the context in as an argument when you call the execute method

    AsyncTask code

    public class DataProcessor extends AsyncTask<Context, Void, Void>{
    
        @Override
        protected Void doInBackground(Context... params) {
    
            Context context = params[0];
    
            DataBaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class)
            // Your code here
        }
    }
    

    Implementation code (for an Activity)

    new DataProcessor().execute(this);
    

    Method 3

    Have a static instance of your context that the Async Task can access directly.
    A way to do that can be found here: Static way to get 'Context' on Android?

    AsyncTask code

    public class DataProcessor extends AsyncTask<Void, Void, Void>{
    
        @Override
        protected Void doInBackground(Void... params) {
    
            DataBaseHelper helper = OpenHelperManager.getHelper(MyApplication.getAppContext(), DatabaseHelper.class)
            // Your code here
        }
    }
    

    Implementation code (for an Activity)

    new DataProcessor().execute(this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have android app . i should pass the data from android to web
I have an Android app that communicates with a server via asynchronous socket connection
I have a android app that is quite simple it fetches data from the
I have android app that talks to server and syncs some data int SQLite
I have a MySQL Database on my server. I need my android app to
I have an Android app that fetches data from the web service using ksoap2,
I have Android client app that communicates with server using Socket . On my
I have an Android app that should open links sent via email. I only
I have an Android app, in which Activities fire long running operations that run
I have PhoneGap app in Android using jQuery. Sometimes I need to upload some

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.