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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:53:55+00:00 2026-05-19T11:53:55+00:00

im making an Android app, i have a service, that update my local DB

  • 0

im making an Android app, i have a service, that update my local DB in background, by downloading data from the remote DB.

i have to put a thread on the service, because i dont know why, when i use a simple handle style bucle on the service it frozen my app during some secs when it is updating the local db. (i have my local db in a dbAdapter on MyApplication class)

OK, then i put a thread on the service, but i dont know why, if i start the service, the thread of the service is frezzing my APP :S. it’s suposed that when u use services and threads code is executed in background and doesnt froze nothing, but in this case is frezzing my app. ¿how to avoid it?

this is the code of my service:

public class MyServiceLocalDB extends Service implements Runnable{

RemoteConnection con; //conexion remota
//para almacenar la config local de mi app
static SharedPreferences settings;
static SharedPreferences.Editor configEditor;
boolean serviceStopped;

private static MyDbAdapter         mDb;

@Override
public IBinder onBind(Intent intent) {
    return null;
}

@Override
public void onCreate() {

    serviceStopped=false;
    settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
    configEditor = settings.edit();
    con = new RemoteConnection(); 
    mDb = new MyDbAdapter(this);
    mDb.open();
}

@Override
public void onDestroy() {
    //player.stop();
    serviceStopped=true;
}

@Override
public void onStart(Intent intent, int startid) {
    //player.start();
    this.run();
}
public void updateDB()
{  

    mDb.clearDB();
    List<Friend> myFriends=con.RetrieveFriends(settings.getString("login",""));
    List<Permission> myPermissions=con.RetrievePermissions(settings.getString("login",""));

    Permission p1 = null;
    for (int i=0;i<myFriends.size();i++)
    {
        mDb.createUser(myFriends.get(i).getEmail(),myFriends.get(i).getFullName(),myFriends.get(i).getMovilephone(),myFriends.get(i).getMovileOperatingSystem(),myFriends.get(i).getPermission());
        //p1=con.RetrievePermissionWithUser("pablo@upv.es", myFriends.get(i).getEmail());
    }
    for (int i=0;i<myPermissions.size();i++)
    {
        p1=myPermissions.get(i);
        String hour1=formatHourFromTime(p1.getHour1());
        String hour2=formatHourFromTime(p1.getHour2());
        mDb.createPermission(p1.getFk_email1(),p1.getFk_email2(),""+p1.getValidated(),hour1,hour2,p1.getDate1Formated(),p1.getDate2Formated(),""+p1.getWeekend(),p1.getFk_type());
        p1=null;
    }

    //MyApplication.getDatabaseAdapter().clearDB();
    MyApplication.setDatabaseAdapter(mDb);

}

public String formatHourFromTime(Time time)
{
    String hour1;
    if (time.getHours()<10)
        hour1="0"+time.getHours();
    else
        hour1=""+time.getHours();
    if (time.getMinutes()<10)
        hour1=hour1+":0"+time.getMinutes()+":00";
    else 
        hour1=hour1+":"+time.getMinutes()+":00";
    return hour1;
}


public void run() {
    while (serviceStopped==false) 
    {
        //handler.sendEmptyMessage(0);
        try {
           Thread.sleep(25000);// sleeps
        } catch (InterruptedException e) {}
        updateDB();
    }   
}

}

  • 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-19T11:53:56+00:00Added an answer on May 19, 2026 at 11:53 am

    The onStart is called by the OS on a main UI thread, that’s why you got stuck there (you block the main UI thread in the run()). Instead of this.run(); you should start a new Thread here – new Thread(this).start();.

    BTW, onStart is deprecated. Implement onStartCommand instead.

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

Sidebar

Related Questions

I have created a simple map app that shows the local garage sales in
I am making an Android app, and I need to connect to a remote
I'm making an Android app using Processing, and have decided to port my code
I'm working on making an iPhone version of an Android app that I've written
I'm making a WinForms app with a ListView set to detail so that several
i am making a app which takes photo on button click i have camera.java
I'm making a calculator-type application and it will have a resulting string that is
In it's simplest explanation, I'm making a really small interactive movie app on Android.
I have a service that is defined as: public class SleepAccelerometerService extends Service implements
I'm making an android app and since I've just started I want to try

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.