我使用此脚本在doInbackground
AsyncTask 中获取注册 ID,但注册 ID 仍然为空。没有错误或强制关闭,但注册 ID 为空。
public class RegisterTask extends AsyncTask<String, Void, Integer> {
public RegisterTask(RegisterActivity activity, ProgressDialog progressDialog) {
this.activity = activity;
this.progressDialog = progressDialog;
}
@Override
protected void onPreExecute() {
progressDialog.show();
}
@Override
protected Integer doInBackground(String... arg0) {
inputFullName = (EditText) activity.findViewById(R.id.registerName);
inputEmail = (EditText) activity.findViewById(R.id.registerEmail);
inputPassword = (EditText) activity.findViewById(R.id.registerPassword);
String name = inputFullName.getText().toString();
String email = inputEmail.getText().toString();
String password = inputPassword.getText().toString();
Log.v(email, password);
UserFunctions userFunction = new UserFunctions();
// Make sure the device has the proper dependencies.
GCMRegistrar.checkDevice(activity);
// Make sure the manifest was properly set - comment out this line
// while developing the app, then uncomment it when it's ready.
GCMRegistrar.checkManifest(activity);
// lblMessage = (TextView) findViewById(R.id.lblMessage);
activity.registerReceiver(activity.mHandleMessageReceiver,
new IntentFilter(DISPLAY_MESSAGE_ACTION));
// Get GCM registration id
regId = GCMRegistrar.getRegistrationId(activity);
JSONObject json = userFunction.registerUser(name, email, password,
regId);
// check for login response
try {
if (json.getString(KEY_SUCCESS) != null) {
// registerErrorMsg.setText("");
String res = json.getString(KEY_SUCCESS);
if (Integer.parseInt(res) == 1) {
// user successfully registred
// Store user details in SQLite Database
DatabaseHandler db = new DatabaseHandler(
activity.getApplicationContext());
JSONObject json_user = json.getJSONObject("user");
// Clear all previous data in database
userFunction.logoutUser(activity.getApplicationContext());
db.addUser(json_user.getString(KEY_ID_USER),
json_user.getString(KEY_NAMA),
json_user.getString(KEY_EMAIL),
json_user.getString(KEY_REGID),
json_user.getString(KEY_JKEL),
json_user.getString(KEY_TLAHIR),
json_user.getString(KEY_INSTANSI),
json_user.getString(KEY_JABATAN),
json_user.getString(KEY_DIBUAT_AT),
json_user.getString(kEY_AVATAR),
json_user.getString(kEY_STATUS));
// successful registration
responseCode = 1;
} else {
// Error in registration
responseCode = 0;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return responseCode;
}
@Override
protected void onPostExecute(Integer responseCode) {
EditText userName = (EditText) activity
.findViewById(R.id.registerEmail);
EditText passwordEdit = (EditText) activity
.findViewById(R.id.registerPassword);
String s = userName.getText().toString();
if (responseCode == 1) {
progressDialog.dismiss();
activity.registerReport(responseCode);
userName.setText("");
passwordEdit.setText("");
}
if (responseCode == 0) {
progressDialog.dismiss();
activity.registerReport(responseCode);
}
}
}
请帮忙