I was implementing a logout feature with Android Studio Firebase.
I created the source code, but it doesn’t respond when I click the button.
The logout button is located in activity_useredit, and if you click the logout button, you will be logged out and then you want to switch to LoginActivity.
But the buttons continue to be unresponsive. Please help me.
The corresponding source code. It’s my first time asking a question here, so I’m inexperienced. I’m sorry.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usereidt);
mFirebaseAuth = FirebaseAuth.getInstance();
logout = (Button) findViewById(R.id.logout);
logout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showLogoutConfirmationDialog();
}
});
}
private void showLogoutConfirmationDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("로그아웃");
builder.setMessage("로그아웃 하시겠습니까?");
builder.setPositiveButton("네", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
mFirebaseAuth.signOut();
Intent intent = new Intent(LogoutActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
});
builder.setNegativeButton("아니요", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
2
Answers
I'm sorry for the slow reply. Thanks to you, I solved it. Thank you!
It looks like there’s a mistake in your code that might be causing the button to be unresponsive. You are trying to start the LoginActivity using an intent with LogoutActivity.this, which is incorrect. Instead, you should use the context of the current activity (which is ActivityUserEdit in your case). Here’s the corrected code:
}
Make sure that the class name ActivityUserEdit matches the name of your activity_usereidt activity class. Also, verify that the logout button in your XML layout file (activity_usereidt.xml) has the correct ID assigned to it.
Additionally, ensure that you have set up the Firebase authentication and added the necessary dependencies to your project to handle authentication. If you’re still facing issues with the button being unresponsive, check for any errors or exceptions in the Android Studio logcat to help identify and resolve any potential issues.