0

I have a service which I call from my mainActivity.

here is the onStart method

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i(TAG, "onStartCommand service");
    stopPolling = false;
    startPolling();
    return super.onStartCommand(intent, flags, startId);
}

now when I start this service from the main activity it runs this method. Now obviously if i am going to block in my startPolling() method it will not return and my main activity will not respond.

How am I meant to start polling ? I am sure that i am missing some simple aspect of an android service which will allow for me to block.

EDIT: I was just reading on the android site and it appears that I have missed a vital sentence: "if your service is going to do any CPU intensive work or blocking operations (such as MP3 playback or networking), you should create a new thread within the service to do that work".

I guess I am going to have to rethink my plan....

4

1 回答 1

1

我该如何开始投票?

好吧,轮询通常被认为是最后的编程技术。理想情况下,找到一些事件驱动的方法来找出你想要找出的任何东西。

除此之外,叉一个线程。

于 2013-10-12T20:21:15.993 回答