I have a web services programmed in PHP and I want to connect to it from the android emulator to verify my cellphone number whit account kit facebook. Up until this point everything works fine but when I have to leave the other activity to register my data set it stays in the waiting dialogue
I thought it could be the
alertdialog.dismiss
the problem but I'm not sure
My BASE_URL is: 10.0.2.2:80/godrink/
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_CODE = 1000;
Button btn_continue;
IGoDrinkAPI mService;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mService = Common.getAPI();
btn_continue = (Button)findViewById(R.id.btn_continue);
btn_continue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Loguearemos con el telefono de celular / movil. > Abrira a la pagina de facebook
startLoginPage(LoginType.PHONE);
}
});
}
private void startLoginPage(LoginType loginType) {
//Estamos pasando con un intent a la activity donde esta para registrarse
Intent intent = new Intent(this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder builder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(loginType,AccountKitActivity.ResponseType.TOKEN);
intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,builder.build());
startActivityForResult(intent,REQUEST_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == REQUEST_CODE)
{
AccountKitLoginResult result = data.getParcelableExtra(AccountKitLoginResult.RESULT_KEY);
if (result.getError() != null)
{
Toast.makeText(this, "Cancel"+result.getError().getErrorType().getMessage(), Toast.LENGTH_SHORT).show();
}
else{
if(result.getAccessToken() != null){
final android.app.AlertDialog alertDialog = new SpotsDialog(MainActivity.this);
alertDialog.show();
alertDialog.setMessage("Please waiting");
//Get User phone and Check exists on server
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(final Account account) {
mService.checkUserExists(account.getPhoneNumber().toString())
.enqueue(new Callback<CheckUserResponse>() {
@Override
public void onResponse(Call<CheckUserResponse> call, Response<CheckUserResponse> response) {
CheckUserResponse userResponse = response.body();
if(userResponse.isExists()){
//If User already exists, just strat new Activity
alertDialog.dismiss();
}
else{
//Else, need register
alertDialog.dismiss();
showRegisterDialog(account.getPhoneNumber().toString());
}
}
@Override
public void onFailure(Call<CheckUserResponse> call, Throwable t) {
}
});
}
@Override
public void onError(AccountKitError accountKitError) {
Log.d("ERROR",accountKitError.getErrorType().getMessage());
}
});
}
}
}
}
private void showRegisterDialog(final String phone) {
final android.app.AlertDialog.Builder alertDialog = new android.app.AlertDialog.Builder(MainActivity.this);
alertDialog.setTitle("REGISTER");
LayoutInflater inflater = this.getLayoutInflater();
View register_layout= inflater.inflate(R.layout.register_layout,null);
final MaterialEditText edt_name = (MaterialEditText)register_layout.findViewById(R.id.edt_name);
final MaterialEditText edt_address = (MaterialEditText)register_layout.findViewById(R.id.edt_address);
final MaterialEditText edt_birthdate = (MaterialEditText)register_layout.findViewById(R.id.edt_birthdate);
Button btn_register = (Button)register_layout.findViewById(R.id.btn_register);
edt_birthdate.addTextChangedListener(new PatternedTextWatcher("####-##-##"));
//Event
btn_register.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Close dialog
alertDialog.create().dismiss();
if (TextUtils.isEmpty(edt_address.getText().toString())) {
Toast.makeText(MainActivity.this, "Please Enter your Address", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(edt_birthdate.getText().toString())) {
Toast.makeText(MainActivity.this, "Please Enter your Birthdate", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(edt_name.getText().toString())) {
Toast.makeText(MainActivity.this, "Please Enter your name", Toast.LENGTH_SHORT).show();
return;
}
final android.app.AlertDialog watingDialog = new SpotsDialog(MainActivity.this);
watingDialog.show();
watingDialog.setMessage("Please waiting");
mService.registerNewUser(phone,
edt_name.getText().toString(),
edt_birthdate.getText().toString(),
edt_address.getText().toString())
.enqueue(new Callback<User>() {
@Override
public void onResponse(Call<User> call, Response<User> response) {
watingDialog.dismiss();
User user = response.body();
if (TextUtils.isEmpty(user.getError_msg())) {
Toast.makeText(MainActivity.this, "User register Successfully", Toast.LENGTH_SHORT).show();
//Start New Activity
}
}
@Override
public void onFailure(Call<User> call, Throwable t) {
watingDialog.dismiss();
}
});
}
});
alertDialog.setView(register_layout);
alertDialog.show();
}
//Generaremos una KEY para nuestra Aplicacion
private void printKeyHash() {
try{
PackageInfo info = getPackageManager().getPackageInfo("com.example.rebcesp.godrink",
PackageManager.GET_SIGNATURES);
for (Signature signature:info.signatures){
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
Log.d("KEYHASH", Base64.encodeToString(md.digest(),Base64.DEFAULT));
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
}
You can only create alerDialog.create() or alertDialog.dismiss()
you can not like this : alertDialog.create().dismiss();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.