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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:37:43+00:00 2026-05-30T11:37:43+00:00

recently I’ve been trying to create pseudo-AciveRecord-style db calls in my android app and

  • 0

recently I’ve been trying to create pseudo-AciveRecord-style db calls in my android app and came up with a bunch of class methods like User.all(Context dbContext), User.find(long id, Context dbContext), User.delete(long id, Context dbContext), etc.
By pseudo-AciveRecord I mean I don’t plan to make it “real ActiveRecord library” or anything like that. I just want to have an easy to understand db calls in my code and ActiveRecord style is the best for me personally.
So far so good and I don’t have any issues having this code for example:

    public static Cursor allAsCursor(Context dbContext) {
    DBHelper dBHelper = new DBHelper(dbContext);
    SQLiteDatabase database = dBHelper.getReadableDatabase();

    Cursor dbQueryResult = database.query(DBHelper.TABLE_NAME_USERS, null, null, null, null, null, "_id DESC");
    dbQueryResult.getCount();

    database.close();
    dBHelper.close();
    dbContext = null;


    return dbQueryResult;
}

But the thing that bothers me is that I pass activity context or something like this all the time when I make a call and I was wondering if it would be a good idea to just give my User class(which has User.find, User.all, etc.) a static variable where it would store application context for every db query? It could be done on app lunch or before the very first query request.

My thinking comes from iOS CoreData thing where you got pretty much static context manager for queries which you get all the time from shared application.

Any thoughts, suggestions, ideas?

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-05-30T11:37:44+00:00Added an answer on May 30, 2026 at 11:37 am

    Its all down to your design preference I guess, since the method is static i’m guessing all of these DB class methods are static so the class is always used in a static way? Also, are you passing in the Activity context or the application context. If you are using the application context then I would add another static method for setting the context and have a private static reference to the context.

    e.g:

    private static Context context;
    
    public static void setContext(Context context){
        YourDBHelperClass.context = context;
    }
    

    Now your method can just reference this context instead of having to be passed one every time you make a transaction.

    If you are passing in an activity context then I would leave it as is otherwise you risk trying to use a stale context.

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

Sidebar

Related Questions

Recently I have been told that static class/methods are evil. Take for example my
Recently I've been doing quite the project mostly working with the DateTime class. Now,..
Recently I have been working with a SQL Server database and I was trying
Recently I became the proud owner of an Android 4.0 tablet and have been
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
Recently our site has been deluged with the resurgence of the Asprox botnet SQL
Recently just upgraded to SQL Server 2008 R2 Express. When I attempt to create
Recently I have been dealing with windows LogonUser API. The LogonUser api returns different
Recently i am making an app on facebook. So i have use facebook api.

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.