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

The Archive Base Latest Questions

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

How do I handle references between Fragments showing list of data and different threads/classes

  • 0

How do I handle references between Fragments showing list of data and different threads/classes updating data in the background. Because of this I need to be able to force update from outside of the Fragments via Observer-inf or something similar.

Currently I’m using dummy factory-class to create a new SqlLiteDatabase object, based on my default settings for it.

public static SQLiteDatabase initFor(Context context) {
    db = context.openOrCreateDatabase(NAME, SQLiteDatabase.CREATE_IF_NECESSARY, null);
    db.setLocale(Locale.getDefault());
    db.setVersion(1);
    db.setLockingEnabled(true);
    return db; }

Then I call this from each fragment and sets up adapters, the same applies to the data-inserter-threads. To close the db, I override my activity’s onDestroy() and call: initFor(this).close(); .

This is very ugly and it fails on orientation change. I’m thinking of SQLiteOpenHelper but I don’t know how it will help me.

  • 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:03:15+00:00Added an answer on June 5, 2026 at 1:03 pm

    You should access your database on another thread (in a Service) then have this talk to one class (which could be your helper), you then access this helper class through a singleton initialized in a class that extends Application. You can get your Application class from any of your fragments by calling

     ((YourApplication) context.getApplicationContext()).getGetDatabaseHelper();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yet another question about updating from background threads. To get to the point: In
I handle commands inside a RoutedCommand class that implements RoutedUICommand. This would help me
I need to handle orientation (Portrait - Landscape) in my application. Basic layout of
I need to handle the case when a user clicks on a mapTypeControl differently
What is the difference between a handle to an object in Managed C++ such
I'm thinking about deploying Doctrine migrations in my environment to handle database changes between
I need to run .Net code in Sql and I'm trying to decide between
How do games with gravity handle the relationship between moving things like players, monsters,
Assume we have a popular site. We need to implement mail-like messaging between users.
My Perl app and MySQL database now handle incoming UTF-8 data properly, but I

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.