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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:28:09+00:00 2026-06-05T14:28:09+00:00

Possible Duplicate: Android Service makes Activity not responding I use service to synchronize data

  • 0

Possible Duplicate:
Android Service makes Activity not responding

I use service to synchronize data between database and view. But the service does not work properly, whenever I use service to work long task, the view stop response (I can’t do any event in UI) and I have to wait the service has done. Here is my service:

public class SyncService extends Service{
private static final String TAG = "SyncService";
@Override
public void onCreate()
{       
    super.onCreate();
}

@Override
public void onDestroy()
{
    super.onDestroy();
}

@Override
public IBinder onBind(Intent intent)
{
    Log.d(TAG, "call onBind");
    return new DataManagerBinder();
}

private class DataManagerBinder extends Binder implements IUserDataManager
{
    @Override
    public void doProcess(Activity mView)
    {
        //do some long task (not touch UI thread)
        // this will cause the view not response
        syncDB();
        // update view after process completed
        mView.updateViewOnComplete();
    }

}

I try to bind this service in client activity

//the interface to handle binder 
IUserDataManager  viewManager = null;    
ServiceConnection serviceConnection = new ServiceConnection()
{

    @Override
    public void onServiceDisconnected(ComponentName name)
    {
        Log.i(TAG, "connection closed unexpectedly");
        viewManager = null;
    }

    @Override
    public void onServiceConnected(ComponentName name, IBinder binder)
    {
        Log.d(TAG, "serviceConnection onServiceConnected");
        viewManager = (IUserDataManager) binder;
        viewManager.doProcess(MyActivity.this);
    }
};

    Intent intent = new Intent(MyActivity.this, SyncService.class);
    bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);

Please give me the solution for that. Thanks in advance!

  • 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-05T14:28:12+00:00Added an answer on June 5, 2026 at 2:28 pm

    While others have given some responses, I don’t know if the main point has been emphasized:
    While a Service sounds like something that would automatically run in the background, it does not. It’s merely a piece of code that can react to intents without maintaining a UI. However, the UI thread still does the processing for the Service.

    By contrast, it looks like what you want, is a Service that sits in the background and does some work in a background thread. You will use the Service class to spawn a new thread, this is typically done on response to some intent, which you can define (usually in your onStart() or something similar). You will probably start a new thread which actually does the work updating the database, etc…, and use your main Service to coordinate to that thread.

    As it looks like you also want to communicate with the service, you will have to implement an appropriate Messenger and Handler pair to keep track of messages you pass between the UI and the Service (coordinating a background thread), and also (possibly) some way (also perhaps a messenger) of coordinating between the Service and the background thread.

    As others have noted, you can also use AsyncTask to do things on the UI thread and use a background thread “seamlessly.”

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

Sidebar

Related Questions

Possible Duplicate: Android: How can I get the current foreground activity (from a service)?
Possible Duplicate: Android Activity Life Cycle - difference between onPause() and OnStop() Can anybody
Possible Duplicate: Android Activity Life Cycle - difference between onPause() and OnStop() What is
Possible Duplicate: Android Button Tooltip Is there any way to construct a view where
Possible Duplicate: Android API for Google Drive? I want to synchronize a single small
Possible Duplicate: Android SMS Receiver not working I am in the beginning stages of
Possible Duplicate: Android: How to resize a custom view programmatically? What's the best way
Possible Duplicate: Android Unknown Command 'crunch' I have been using eclipse just fine but
Possible Duplicate: Android AdMobs problem. I am trying to put in an ad but
Possible Duplicate: Android: automatically choose debug/release Maps api key? I use MapView in my

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.