每当我通过简单地编写Toast按下警报对话框的肯定按钮时,它就可以正常工作并且可见Toast,但是如果我对肯定按钮执行任何操作,则该操作将被执行,但与此同时,我的应用程序也会崩溃。
disire:-我只想平稳运行我的应用程序,即按下肯定按钮后,它应该显示所需的Toast消息,并只需执行所需的操作即可关闭警报对话框。
下面是logcat中显示的错误。
java.lang.RuntimeException: Performing stop of activity that is not resumed:
{com.android.launcher3/com.android.launcher2.Launcher}
代码段是这样的。
sendingPassword=FirebaseAuth.getInstance();
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
LayoutInflater inflater=getActivity().getLayoutInflater();
final View view=inflater.inflate(R.layout.dialogue_layout,null);
builder.setView(view)
.setTitle("forget password")
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
})
.setPositiveButton("send", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
forgetEmail=view.findViewById(R.id.forgetpasswordarea);
sendingPassword.sendPasswordResetEmail(forgetEmail.getText().toString().trim())
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful())
{
Toast.makeText(getActivity(),"check your email for link",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getActivity(),task.getException().getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}
});
return builder.create();
}