facebook, android java.lang.IllegalStateException: Cannot execute task: the task is already running

a 夏天 提交于 2019-12-19 00:55:19

问题


After login I can I can make FB queries. After few minutes (played game) Facebook requests fail exception:

java.lang.IllegalStateException: Cannot execute task: the task is already running

It fails when I call

        Request.executeMeRequestAsync(Session.getActiveSession(),
                new Request.GraphUserCallback() {...

        Request.executeGraphPathRequestAsync(Session.getActiveSession(),
                "me/apprequests", new Request.Callback() {...

        Request request = new Request(session, "me/apprequests", null,
                    null, new Request.Callback() { .... } );
        RequestAsyncTask status = request.executeAsync();

Same calls are called immediately after login and they work. I have a test app where it works. But in real app after few minutes after login it does not work.


回答1:


Are you running on UI thread? Wrap your code withrunOnUiThread

like this

Facebook SDK mentions that async calls must be done from UI thread




回答2:


You can use Request.toHttpConnection(request) instead of request.executeAsync()



来源:https://stackoverflow.com/questions/15556015/facebook-android-java-lang-illegalstateexception-cannot-execute-task-the-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!