我遇到了一些奇怪的警告與asynctask.I'm學習GCM,所以我嘗試使用asynctask。 這是警告:Asynctask奇怪的行爲
Type safety: The method execute(Object...) belongs to the raw type AsyncTask. References to generic type AsyncTask<Params,Progress,Result> should be parameterized
我想了解的這個warning.IS它有關線程。爲什麼它不是安全的意義?這是什麼原料?
這是我的代碼:
private void registerInBackground() {
// TODO Auto-generated method stub
new AsyncTask() {
@Override
protected Object doInBackground(Object... arg0) {
// TODO Auto-generated method stub
String msg = "";
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
}
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.
// The request to your server should be authenticated if your app
// is using accounts.
sendRegistrationIdToBackend();
// 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.
// Persist the regID - no need to register again.
storeRegistrationId(getApplicationContext(), regid);
} catch (IOException ex) {
msg = "Error :" + ex.getMessage();
// If there is an error, don't just keep trying to register.
// Require the user to click a button again, or perform
// exponential back-off.
}
return msg;
} @Override
protected void onPostExecute(Object result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
Toast.makeText(getApplicationContext(), ""+result.toString(), Toast.LENGTH_LONG).show();
}
}.execute(null, null, null);
}
感謝
現在的工作。 非常感謝 –