在創建GCM客戶端應用程序時,asynctask正在給出編譯錯誤。 OnCreate我們正在調用registerBackgrouod,它將檢查gcm實例是否正在運行,如果沒有創建一個。創建GCM客戶端應用程序,asynctask失敗
但asyntask是給錯誤:「的AsyncTask不能被解析爲一個類型」
private void registerBackground() {
new AsyncTask() {
protected String doInBackground(Void... params) {
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
msg = "Device registered, registration id=" + regid;
// You should send the registration ID to your server over HTTP,
// so it can use GCM/HTTP or CCS to send messages to your app.
// For this demo: we don't need to send it because the device
// will send upstream messages to a server that echo back the message
// using the 'from' address in the message.
// Save the regid - no need to register again.
setRegistrationId(context, regid);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
}
return msg;
}
protected void onPostExecute(String msg) {
mDisplay.append(msg + "\n");
}
}.execute(null, null, null);
應該是'新的AsyncTask <太虛,太虛, String>()' – AlexBcn
它沒有工作,使用線程和thread.start()而不是asynctask工作。 – John
Android文檔已損壞。跟蹤器中有一個錯誤報告,但我不知道他們什麼時候會修復它。 – Xeos