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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:18:32+00:00 2026-06-16T18:18:32+00:00

I have created a widget application, in which I use SQLite database object which

  • 0

I have created a widget application, in which I use SQLite database object which is initialized when user enable his widget. I declare Database object as static as in other case it become null just after onReceive() method called and my application crashes.

Now I am using mDatabase object in onReceive() method and everything works except:

  1. Is it normal to keep static member of Database in the Widget or there is more correct way to do that?
  2. After some time of using application (one day or two) my application crashes, look like some members become null (may be mDatabase), I think if you answer my first question it will be answer for second too 🙂

Code example

public class Widget extends AppWidgetProvider {

    private static DatabaseObject mDatabase = null;
    private static int mIndex = 0;

    @Override
    public void onEnabled(Context context) {
        mDatabase = new DatabaseObject (context);
        mDatabase.initialize("Some data"); 
    }

    @Override
    public onReceive(Context context, Intent intent)
    {
        // Some code ....
        mDatabase.getItemAtIndex(mIndex);
        mIndex++;
    }

};
  • 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-16T18:18:33+00:00Added an answer on June 16, 2026 at 6:18 pm

    You are not supposed to do long lasting operations in onReceive(). You should start a service (IntentService) that updates your widget and do your DB work there. Also keep in mind that your app’s activities and services can be killed at any time, so you need to handle this. If you need to access your DB helper class (DatabaseObject) make it a singleton and it will be available for the while lifecycle of your process.

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

Sidebar

Related Questions

I have created a Qt application which brings up a transparent widget. I have
I have created a widget in my application , now when a widget is
I have an application which makes use of the default camera to take pictures
I have created an app widget which, when clicked, launches an Activity in my
I have created an App Widget for Android 1.5. It uses a TextView to
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
i have created a custom post type named Books & i have a widget
I have a CLI application, which is digging some data, in case of need,
I have an application which I am developing using WPF\Prism\MVVM. All is going well
I want to produce a simple enough application which uses a QTreeView widget to

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.