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

  • Home
  • SEARCH
  • 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 8070763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:30:13+00:00 2026-06-05T13:30:13+00:00

I use OrmLite and I want to get the helper class (and then get

  • 0

I use OrmLite and I want to get the helper class (and then get a dao class) in a class which doesn’t extend OrmLiteBaseActivity.

I read the documentation on using with Android and I looked at their no base class example.

As my class isn’t an Activity :

  1. it isn’t a Context, so OpenHelperManager.getHelper can’t work.

    I know I can get the context from every part of my application using the application but is there a better way ?

  2. it doesn’t have a onDestroy to override.

    I can put the logic at the end of my function :

    if (databaseHelper != null) {
        OpenHelperManager.releaseHelper();
        databaseHelper = null;
    }
    

    But if my class become more complex, what is the good behaviour ?

Regards.

  • 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-05T13:30:17+00:00Added an answer on June 5, 2026 at 1:30 pm

    The general rule of thumb is that you should create a single helper object and then release it when all of the parts of your program are done with it. This means that if you have different threads that are using the helper, you’ll need to keep some sort of usage counter — maybe with AtomicInteger. As each class asks for the helper, the first time it is created but every time afterwards the counter is increased. As they are done with the helper they decrement the counter. When the counter goes to 0 you release it from OpenHelperManager.

    it isn’t a Context, so OpenHelperManager.getHelper can’t work.

    You are going to need to get the Context somehow. Using the application should be fine as long as it works.

    it doesn’t have a onDestroy to override

    But part of your program does have onDestroy. You are going to have to application the other parts of your application from the places that do have onDestroy — maybe by calling a static destroy() method.

    But if my class become more complex, what is the good behaviour?

    I don’t see any problems with the above even with complex applications. If you’d like maybe setup a register/unregister type of config so as your classes construct they register with some central class which then shuts them down at the end.

    Hope some of this helps.

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

Sidebar

Related Questions

I am programming an Android app and using ormLite for the database. I want
Use: The user searches for a partial postcode such as 'RG20' which should then
Use case: we have some project meta-data files which we want tracked, but are
I use ormlite with android and I've some poco class. Example : public class
I'm using ORMLite on Android, and have 7 tables in which I need to
How should I use proguard with ormlite library on Android? Trying this: -keep class
use C#,want to upload excel file on google doc. bellow syntax use to upload
Why do I get the error-message? #!/usr/bin/env perl use warnings; use 5.012; use ORLite
use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( $url ); say $mech->text; How could I
I am looking for a good introductory tutorial on how to use ORMLite with

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.