我有一个允许我登录和退出的应用程序。退出按钮现在似乎会崩溃应用程序当我按下它之前工作正常。它仍然会退出用户,当您返回应用程序时,您必须再次登录。
我在下面的创建方法中添加了我的整体,其中动作发生在底部。只是因为我添加了一个副本或我缺少的东西
//view objects
private TextView textViewUserEmail;
private Button buttonLogout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
buttonAddProducts = (Button) findViewById(R.id.buttonAddProducts);
buttonAddBeverages = (Button) findViewById(R.id.buttonAddBeverages);
buttonLogout = (Button) findViewById(R.id.buttonLogout);
firebaseAuth = FirebaseAuth.getInstance();
buttonAddProducts.setVisibility(View.GONE);
buttonAddBeverages.setVisibility(View.GONE);
databaseUsers = FirebaseDatabase.getInstance().getReference("users");
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
DatabaseReference currentUserReference = databaseUsers.child(uid);
currentUserReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot userSnapshot) {
if (userSnapshot.exists()) {
User user = userSnapshot.getValue(User.class);
if(user.getAdminUser() == true)
{
buttonAddProducts.setVisibility(View.VISIBLE);
buttonAddBeverages.setVisibility(View.VISIBLE);
}
}
else{
Log.i("myInfoTag", "Connection problem");
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
throw databaseError.toException(); // don't ignore exceptions
}
});
//if the user is not logged in
//that means current user will return null
if(firebaseAuth.getCurrentUser() == null){
//closing this activity
finish();
//starting login activity
startActivity(new Intent(this, LoginActivity.class));
}
//getting current user
FirebaseUser user = firebaseAuth.getCurrentUser();
//initializing views
textViewUserEmail = (TextView) findViewById(R.id.textViewUserEmail);
//displaying logged in user name
textViewUserEmail.setText("Welcome "+user.getEmail());
buttonLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//logging out the user
firebaseAuth.signOut();
//closing activity
finish();
//starting login activity
startActivity(new Intent(ProfileActivity.this, SignUpActivity.class));
}
});
}
当我按下退出时,它只是因为msg啤酒应用已经停止而崩溃
答案 0 :(得分:0)
以下代码块不会立即将执行转移到已启动的活动。它只启动该流程,并继续执行以下语句。
qsub job1.sh #DONE
qsub job2.sh #DONE
qsub job3.sh #DONE
qsub job4.sh
在您的情况下,以下某个语句为 if(firebaseAuth.getCurrentUser() == null){
//closing this activity
finish();
//starting login activity
startActivity(new Intent(this, LoginActivity.class));
}
,如果没有用户登录,则会引发user.getEmail()
。