gpt4 book ai didi

java - 加载时出现对话框 "keep' s 后无法进入第二个 Activity ”

转载 作者:行者123 更新时间:2023-12-02 11:06:23 26 4
gpt4 key购买 nike

在我的主要 Activity 上出现“继续加载”对话框后,无法进入第二个 Activity ,并且可以加载几个小时而不会出现错误我使用 facebook acount 套件,我没有看到错误,这里是主要 Activity 源代码主要 Activity java:

公共(public)类 MainActivity 扩展 AppCompatActivity {

private static final int REQUEST_CODE = 1000;
Button btnContinue;
RelativeLayout rootLayout;

FirebaseAuth auth;
FirebaseDatabase db;
DatabaseReference users;

@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//bf4 set context view
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Arkhip_font.ttf")
.setFontAttrId(R.attr.fontPath)
.build());
setContentView(R.layout.activity_main);


printKeyHash();

//Init Firebase
auth = FirebaseAuth.getInstance();
db = FirebaseDatabase.getInstance();
users = db.getReference(Common.user_driver_tbl);

//init view
btnContinue = (Button)findViewById(R.id.btnContinue);

rootLayout =(RelativeLayout)findViewById(R.id.rootLayout);


//Event
btnContinue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
signInwithPhone();
}
});


//auto login to facebook act kit for second time
if (AccountKit.getCurrentAccessToken() != null)
{
//create dialog
final AlertDialog waitingDialog = new SpotsDialog(this);
waitingDialog.show();
waitingDialog.setMessage("Please waiting....");
waitingDialog.setCancelable(false);

AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(Account account) {
//copy from exiting user
users.child(account.getId())//fixed
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Common.currentUser = dataSnapshot.getValue(User.class);

Intent homeIntent = new Intent(MainActivity.this,DriverHome.class);
startActivity(homeIntent);

//Dismiss dialog
waitingDialog.dismiss();
finish();
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});
}

@Override
public void onError(AccountKitError accountKitError) {

}
});
}

}

private void signInwithPhone() {
Intent intent = new Intent(MainActivity.this, AccountKitActivity.class);
AccountKitConfiguration.AccountKitConfigurationBuilder configurationBuilder =
new AccountKitConfiguration.AccountKitConfigurationBuilder(LoginType.PHONE,
AccountKitActivity.ResponseType.TOKEN);
intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION,configurationBuilder.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, ""+result.getError().getErrorType().getMessage(), Toast.LENGTH_SHORT).show();
return;
}
else if (result.wasCancelled())
{
Toast.makeText(this, "Cancel login", Toast.LENGTH_SHORT).show();
return;
}
else{
if (result.getAccessToken() !=null)
{
//Show dialog
final AlertDialog waitingDialog = new SpotsDialog(this);
waitingDialog.show();
waitingDialog.setMessage("Please waiting....");
waitingDialog.setCancelable(false);

//get current phone
AccountKit.getCurrentAccount(new AccountKitCallback<Account>() {
@Override
public void onSuccess(final Account account) {
final String userId = account.getId();

//check if exist on firebase
users.orderByKey().equalTo(account.getId())
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (!dataSnapshot.child(account.getId()).exists())//if not exits
{
//will we create new user login
final User user = new User();
user.setPhone(account.getPhoneNumber().toString());
user.setName(account.getPhoneNumber().toString());
user.setAvatarUrl("");
user.setRates("0.0");

//Register to Firebase
users.child(account.getId())
.setValue(user)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {

//Login
users.child(account.getId())
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Common.currentUser = dataSnapshot.getValue(User.class);

Intent homeIntent = new Intent(MainActivity.this,DriverHome.class);
startActivity(homeIntent);

//Dismiss dialog
waitingDialog.dismiss();
finish();
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});

}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
else //if user existing ,login
{
users.child(account.getId())
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Common.currentUser = dataSnapshot.getValue(User.class);

Intent homeIntent = new Intent(MainActivity.this,DriverHome.class);
startActivity(homeIntent);

//Dismiss dialog
waitingDialog.dismiss();
finish();
}

@Override
public void onCancelled(DatabaseError databaseError) {

}
});


}
}

@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}

@Override
public void onError(AccountKitError accountKitError) {
Toast.makeText(MainActivity.this, ""+accountKitError.getErrorType().getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
}

private void printKeyHash() {
try{
PackageInfo info = getPackageManager().getPackageInfo("com.example.rd.androidapp",
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();
}
}

}

如果需要更多!或者是否还缺少一些东西,我在 Android 编程方面还是个新手,所以......

最佳答案

尝试使用 onCancel 和 onError 方法中的关闭对话框并打印错误来判断。

关于java - 加载时出现对话框 "keep' s 后无法进入第二个 Activity ”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50928104/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com