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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:29:19+00:00 2026-06-05T09:29:19+00:00

i yet really grasp this whole context thing we found a lot in android

  • 0

i yet really grasp this whole context thing we found a lot in android programming. so i tried creating a function to drop all my tables, and here’s a my partial code:

public class DBAdapter {
       private static class DbHelper extends SQLiteOpenHelper {
        private boolean databaseCreated = false;
        public DbHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        public void deleteTables(){
        Log.d("DBAdapter","dlm drop tables pre");
        this.sqlDatabase.execSQL("DROP TABLE IF EXISTS ["+TABLE_TV+"];");
        this.sqlDatabase.execSQL("DROP TABLE IF EXISTS ["+TABLE_CAMERA+"];");
        this.sqlDatabase.execSQL("DROP TABLE IF EXISTS ["+TABLE_GPS+"];");
       }
}
}

and the part where i’m going to call the function deleteTables

public class UpdateDatabase {
     public void updateTable(String table,JSONObject jsonObject){
    DBAdapter db = new DBAdapter(this);
        db.deleteTables();
    }
}

but of course it will return an error, since DBAdapter expects a context. public class UpdateDatabase is not an activity class. Calling DbAdapter db = new DBAdapter(this) from activity class will work just find. So how do I find any fix for this problem?

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-05T09:29:20+00:00Added an answer on June 5, 2026 at 9:29 am

    You can add a constructor to UpdateDatabase that takes a Context and stores it so that it is available to be used by updateTable. Something like this:

    public class UpdateDatabase {
        private final Context mContext;
    
        public UpdateDatabase(Context context){
            mContext = context;
        }
    
        public void updateTable(String table,JSONObject jsonObject){
            DBAdapter db = new DBAdapter(mContext);
            db.deleteTables();
        }
    }
    

    Now, whenever you do new UpdateDatabase() you will need to do new UpdateDatabase(..context..) instead. If you are doing this from an Activity, then you can do new UpdateDatabase(this).

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

Sidebar

Related Questions

This has been annoying me for a while yet the solution must be really
Not really a requirement or anything yet, but can you do this in a
This has driven me really bananas. It's so simple and easy and yet I
EDIT: Problem solved. This was (yet another) situation where the problem wasn't really where
The lightbulb has yet to go on for this... I'd really love an easy
This sounds really basic yet I couldn't find the answer. I pass a Message
Since it's really not possible to return a single embedded document (yet), what is
I'm having a really annoying problem, the answer is probably very simple yet I
I'm relatively new to Objective-C and really don't know much about it yet, so
I'm playing around with drawing jbox2d objects onto a surfaceview, yet I'm not really

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.