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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:42:04+00:00 2026-05-22T19:42:04+00:00

i am using a background service that it is retrieving data and inserting data

  • 0

i am using a background service that it is retrieving data and inserting data on a remote server. OK, i puted it on a background service because i wanted to get that done in background without slowing down my app, but it is slowing down my app !

as you will see in the code, it haves a sleep of 60 seconds, and my app is getting frozen 2/3 seconds each 60 seconds, it is this code, i am sure, but i dont know how to solve it

public class MyService extends Service implements Runnable{
    boolean serviceStopped;
    RemoteConnection con; //conexion remota
    List <Position> positions;
static SharedPreferences settings;
static SharedPreferences.Editor configEditor;
    private Handler mHandler;
    private Runnable updateRunnable = new Runnable() {
        @Override public void run() {
            //contenido
            if (serviceStopped==false)
            {
                positions=con.RetrievePositions(settings.getString("login","")); //traigo todas las posiciones
                if (positions.size()>=10) //si hay 10 borro la mas vieja
                    con.deletePosition(positions.get(0).getIdposition());
                if (settings.getString("mylatitude", null)!=null && settings.getString("mylongitude", null)!=null)
                    con.insertPosition(settings.getString("mylatitude", null),settings.getString("mylongitude", null), formatDate(new Date()), settings.getString("login",""));
            }
            queueRunnable();//duerme
        }
    };
    private void queueRunnable() {
        //mHandler.postDelayed(updateRunnable, 60000); //envia una posicion al servidor cada minuto (60.000 milisegundos es un minuto)
        mHandler.postDelayed(updateRunnable, 60000);
    }

    public void onCreate() {
        serviceStopped=false;
settings = PreferenceManager.getDefaultSharedPreferences(this.getApplicationContext());
        configEditor = settings.edit();
        positions=new ArrayList<Position>();
        con = new RemoteConnection();
            mHandler = new Handler();
            queueRunnable();
        }
  • 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-22T19:42:05+00:00Added an answer on May 22, 2026 at 7:42 pm

    Even if you created a service it doesn’t mean it will run on a separate thread. Take a look http://developer.android.com/reference/android/app/Service.html

    Note that services, like other application objects, run in the main thread of their hosting process. This means that, if your service is going to do any CPU intensive (such as MP3 playback) or blocking (such as networking) operations, it should spawn its own thread in which to do that work. More information on this can be found in Processes and Threads. The IntentService class is available as a standard implementation of Service that has its own thread where it schedules its work to be done.

    Please take some time to read how services actually work in Android http://developer.android.com/guide/topics/fundamentals/services.html

    So, IntentService and scheduled alert can be a solution here.

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

Sidebar

Related Questions

Background : I have a C# Windows Forms application that contains a Windows service
I want to implement a Web Service that will allow users to store arbitrary
Given a Database that has a table Called [Bid Transactions], which contains records of
I am building an mobile app ( RSS reader ) for Android with Sencha
My app needs to have an updated light level value (a 10-15 minute delay
I am working on a project and am at a point where I am
I'm trying to figure out a way to log off users in local Windows
I've been working with Android for just a couple of weeks now and have
I am currently developing a application which is capable of locating nearby bus and
I am trying to create an MP3 Player where the music carries on playing

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.