views:

46

answers:

1

Hi,

anybody knows what can be the reason for when i start a service from an Activity, the emulator shows a message "the activity is not responding?"

Inside my Service i start 2 threads in order to make some tasks. can be this the cause of the problem?

Thanks

+1  A: 

anybody knows what can be the reason for when i start a service from an Activity, the emulator shows a message "the activity is not responding?"

Because something in your application -- the activity, the service, etc. -- is tying up the main application thread.

Inside my Service i start 2 threads in order to make some tasks. can be this the cause of the problem?

Not directly, no, though you really should consider using AsyncTask rather than forking your own threads

Doing long-running work on the main application thread, or tying it up with a sleep() or busy-loop, will cause this exception.

CommonsWare
hi again, now i have removed all threads in the service, but the problem still happens.My Service connect to an external API and take data from it. I do this task in background..but when i start the service my activity shows the message "not responding".Since the service doesn't tie the main app (i don't have threads), i don't know what can be the problem
xger86x
"My Service connect to an external API and take data from it." -- that needs to be done in an `AsyncTask` or on a background thread. "Since the service doesn't tie the main app" -- yes, it does. "i don't have threads" -- that is your problem. "i don't know what can be the problem" -- work you do, by default, is on the main application threads. Activities run on the main application thread. Services run on the main application thread. Get your slow "external API" calls into an `AsyncTask`. See http://github.com/commonsguy/cw-android/tree/master/Service/WeatherPlus/ for an example.
CommonsWare
ok i'll try it and tell you if it works. thank u
xger86x