我使用的AsyncTask结束,这样我想要的功能将立即执行,不会等到要执行到底..的AsyncTask执行的功能
,但由于某种原因,我为什么不执行在所有的过程结束!
我看了看其他的解决方案,发现线程应该在年底执行,但对于每次的AsyncTask它被称为应当执行..
这里是我的代码
private void LogMeIn()
{
string CheckValue;
// Here I call the AsyncTask
new GCM().execute(null,null,null);
//gcmRegID is a public variable and should has GCM value assigned to it by now, but I it is empty as GCM() has not been executed yet
//This is always return empty string
CheckValue = gcmRegID;
}
这是那的AsyncTask等到年底执行
//This is the AsyncTask
private class GCM extends AsyncTask<String, String, String> {
private String resp;
private Context context;
@Override
protected String doInBackground(String... params) {
GCMHelper gcmRegistrationHelper = new GCMHelper (
getApplicationContext());
try {
gcmRegID = gcmRegistrationHelper.GCMRegister("123456789");
} catch (Exception e) {
e.printStackTrace();
}
return gcmRegID;
}
}
我试图把呼吁GCMRegister在onPreExecute,但我得到的是它必须是在主要的错误螺纹
这就像我在圈子里我要去....
调用必须是在主线程和主线程将在函数结束时执行...
它是没有办法让中间的GCM代码!!!!
我怎样才能使这个AsyncTask执行时,它叫?
感谢
会立即执行。但你没有做任何事情。应该更好地查看文档。 –
“gcmRegID是一个公共变量,应该有现在分配给它GCM值” - 不,它不应该,因为你的任务是异步运行,这意味着它不会阻止,并经过'执行行()立即进行呼叫。 –
你在哪里调用'LogMeIn()'?尝试使用断点。 – petey