下面给出的代码:
private void registerBackground(){
Toast toast3 = Toast.makeText(context,"-----in regbackground class---------",Toast.LENGTH_LONG);
toast3.show();
new AsyncTask<Void,Void,String>(){
@Override
protected String doInBackground(Void... params) {
String msg = "";
Toast toast = Toast.makeText(context, "---out of try ---"+msg, Toast.LENGTH_LONG);
toast.show();
try {
if (gcm == null) {
gcm = GoogleCloudMessaging.getInstance(context);
}
regid = gcm.register(SENDER_ID);
Toast toast1 = Toast.makeText(context, "---regid ---"+regid+"----from background---toast 1", Toast.LENGTH_LONG);
toast1.show();
msg = "Device registered, registration id=" + regid;
Toast toast2 = Toast.makeText(context, "---regid ---"+msg+"----from background---toast 2", Toast.LENGTH_LONG);
toast2.show();
setRegistrationId(context, regid);
} catch (IOException ex) {
msg = "Error ::" + ex.getMessage();
Toast toast4 = Toast.makeText(context,msg+"---error msg",Toast.LENGTH_LONG);
toast4.show();
}
return msg;
}
@Override
protected void onPostExecute(String msg) {
mDisplay.append(msg + "\n");
Toast toast5 = Toast.makeText(context,msg+"---on post execute",Toast.LENGTH_LONG);
toast5.show();
}
}.execute(null);
}
这是我的整个代码。问题是唯一的 toast3 正在执行之后没有执行 Asynctask 方法