Jacob
Jacob

Reputation: 15297

Android service stopps the main UI thread

There is android service listening for bluetooth socket connection.

This connection is realized in permanent loop where commands are received.

This service is started and bounded in activity onStart() with:

 intent.putExtras(b);
        getActivity().startService(intent);
        getActivity().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);

any idea why the main thread is getting stopped?

Upvotes: 0

Views: 190

Answers (1)

Lawrence Aiello
Lawrence Aiello

Reputation: 4638

Because like you said, you have a permanent loop in your main thread. If no bluetooth connections come through, it will wait forever and stall your application.

Use the Runnable thread class and spawn your bluetooth service on another thread so the UI can still run even if no bluetooth connections come through.

Upvotes: 0

Related Questions