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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:25:32+00:00 2026-06-08T00:25:32+00:00

Imagine a app showing the user statistics. I could have an Object like: public

  • 0

Imagine a app showing the user statistics. I could have an Object like:

public class Statistic {
     private int id,value;
}

Where the value should persist between different app executions. Using an database for the persistent system the databaseAdapter could have a:

public void saveStatisticValue(int id,int newValue);
public int getStatisticValue(int id);

Using that calls to the DataBase Adapter in the getter/setter method of the object could impact in the app performance if called from the UI thread due to the database delay. For example if I want to show an Activity with all the Statistics, the database delay of the getter of each Statistic object could result in a ANR.

public class Statistic {

    ....

    public synchronized void setValue(int newValue) {
        dbAdapter.saveStatisticValue(this.getId(),newValue);
    }
    public synchronized int getValue() {
        return dbAdapter.getStatisticValue(this.getId());
    }

    ....

 }

Is there some kind of approach for reduce the database impact for this kind of models?

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-08T00:25:34+00:00Added an answer on June 8, 2026 at 12:25 am

    As you already has observed, the geter/setter method to the Models should be asynchronized.

    For example , the API to getter_statics could be :

    Request getStatics(RequestCallback callback);
    
    interface RequestCallback {
            void notify(int id ,int value);
    }
    

    The requestCallback will be called in the same thread as the getStatics has been called, usually it is the UI thread.

    Two class are provided in Android facilitate you to implement this common pattern: Handler and SyncTask. Please read the document to get a thorough understanding.

    You can also to check out this article.

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

Sidebar

Related Questions

I have the simplest PhoneGap app one could imagine! All I'm trying to do
Im playing a little bit with heavy-client app. Imagine I have this model: class
Imagine you are developing a Java EE app using Hibernate and JBoss. You have
Imagine an in-house application aimed at the very technical user. The app maintains data.
I have a vertically scrolling uiscrollview - imagine an 'about this app' page of
Imagine you have one page app using Javascript MVC, which should switch between sub-apps
Imagine an iPhone app with 30 classes. Every class has to interact with every
Context: Imagine that you have a standard CherryPy hello word app: def index(self): return
I have been busy creating an app for Red5. Imagine what was my surprise
Imagine I have a C# app sitting on a server somewhere that is creating

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.