-3
로그인 및 로그 아웃 할 수있는 앱이 있습니다. 이전에 로그 아웃 버튼이 작동 할 때 앱을 눌렀을 때 앱이 다운되는 것 같습니다. 그것은 여전히 사용자를 로그 아웃하고 앱에 다시 로그인 할 때 다시 로그인해야합니다.로그 아웃하면 내 응용 프로그램이 다운 됨
아래에서 작업을 수행하는 아래의 작성 메소드에 전체 내용을 추가했습니다. 난 그냥
로그인 및 로그 아웃 할 수있는 앱이 있습니다. 이전에 로그 아웃 버튼이 작동 할 때 앱을 눌렀을 때 앱이 다운되는 것 같습니다. 그것은 여전히 사용자를 로그 아웃하고 앱에 다시 로그인 할 때 다시 로그인해야합니다.로그 아웃하면 내 응용 프로그램이 다운 됨
아래에서 작업을 수행하는 아래의 작성 메소드에 전체 내용을 추가했습니다. 난 그냥
을 중단 한 MSG 맥주 응용 프로그램과 충돌 로그 아웃 누르면 내가
//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));
}
});
}
을 잃었 중복 또는 무언가를 추가 한 그냥 넣다 코드의 다음 블록은 즉시 전송을 발생하지 않습니다 시작된 활동에 대한 실행. 해당 흐름을 시작하고 실행은 다음 문으로 계속됩니다. 귀하의 경우에는
if(firebaseAuth.getCurrentUser() == null){
//closing this activity
finish();
//starting login activity
startActivity(new Intent(this, LoginActivity.class));
}
다음 문 중 하나는 로그인 한 사용자가.이없는 경우 NullPointerException
오류가 무엇인지 우리에게 얘기를하려고 발생합니다,
user.getEmail()
입니까? –