2013-04-05 140 views
0

我在我的android应用程序中使用AsyncTasks。Android AsyncTask问题:doInBackground不执行

当我必须通过BroadcastReceiver设置一个Service(AlarmManager)并退出应用程序并重新打开应用程序时,AsyncTask才会执行。

我该如何解决这个问题?我认为有一些线程或任务没有完成,导致这种问题。

+3

发布您用来启动AsyncTask的代码。 – 2013-04-05 17:38:25

回答

0

这可能是因为从Honeycomb(以及之前的甜甜圈)AsyncTask's在单个线程上被串行执行。你有没有其他长期运行的AsyncTasks可能会阻塞新的?

+0

是的,我有,我找到了答案!我只是这样做: [code] authenticationTask = new AuthenticationTask(this,String.valueOf(representante.getCodigo()),representante.getSenha(),PedMobileUtils.decrypt(representante.getSenha())); \t \t \t \t \t \t \t \t \t \t如果(Build.VERSION.SDK_INT> = Build.VERSION_CODES.HONEYCOMB)\t \t \t \t \t \t \t \t \t \t \t authenticationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,(VOID [ ])空值); \t \t \t \t \t \t \t \t别的 \t \t \t \t \t \t authenticationTask.execute(); [/ code] – erickles 2013-04-05 18:11:57

+0

是的,我有,我找到了答案!我只是做了这个,问题解决了! (),String.valueOf(representante.getCodigo()),representante.getSenha(),PedMobileUtils.decrypt(representante.getSenha())); \t \t \t \t \t \t \t \t \t \t如果(Build.VERSION.SDK_INT> = Build.VERSION_CODES.HONEYCOMB)\t \t \t \t \t \t \t \t \t \t \t authenticationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR,(VOID [ ])空值); \t \t \t \t \t \t \t \t别的 \t \t \t \t \t \t authenticationTask.execute(); Thx很多! – erickles 2013-04-05 18:13:44

+0

看来我的回答是正确的(请标记为已回答)。您的其他AsyncTasks之一被阻止。你的解决方案是使用一个使用另一个线程的线程池。通常,如果您想要长时间运行的任务,则不应使用AsyncTask文档中所述的AsyncTask。 – dhaag23 2013-04-06 07:01:07

相关问题