开发者

MonoDroid Looper.MyQueue() hangs on some activities / Idle Handler?

I'm using MonoDroid Looper.MyQueue().AddIdleHandler() to execute some Commands when the app is in idle mode. This is working in one activity, but if I'm starting the second activity it hangs until i touch the screen or restart the first activity. Ther开发者_如何学Pythones no loop or anything which could block the queue in the second activity. How can i prevent the looper from hanging?

Looper.MyQueue().AddIdleHandler(new ExecuteRunner(appState));
public class ExecuteRunner : Java.Lang.Object, MessageQueue.IIdleHandler
{
    int count = 0;
    ApplicationState appState;
    public ExecuteRunner(ApplicationState pAppState)
    {
        appState = pAppState;
    }

    public bool QueueIdle()
    {
        appState.YooManager.Manager.ExecuteCommand();
        count++;
        Android.Util.Log.Debug("YooBik-Exe", count.ToString());
        return true;
    }
}

Could the message queue be blocked by something? In the activity where the idle handler isn't working the OnTouch event is registered.

Or does anybody know another way how to implement an idle handler for monodroid?


If it hangs until you touch screen I guess it waits on MessageQueue.next() ( line this.wait(); ). Because your main activity looper.loop() calls MessageQueue.next() and what it does : while(ture) { 1. pullNextLocked() and returns if there is some msg to execute. otherwise : 2. execute all queueIdle()'s. and then 3. this.wait(); <---------- this is where it wait's. }

If you press touch then MessageQueue.enqueueMessage(Message <-- touch msg ) is called and executes this.notify() which makes point 3 is brings back to life and then point 1, and 2 ( your queueIdle() is executed )

To hack it you can send some nonsense message form the activity to it self which will kick MessageQueue.enqueueMessage and the MessageQueue.next() loop will be awaken.

Best regards, Zbyszek


Not sure if it's causing your problem or not, but you need ExecuteRunner to inherit from Java.Lang.Object and remove your implementation of Handle. When the system calls your Handle method, it will throw an unhandled exception and cause your thread/app to die.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜