通道被不可恢复地破坏并将被处理

Posted

技术标签:

【中文标题】通道被不可恢复地破坏并将被处理【英文标题】:Channel is unrecoverably broken and will be disposed 【发布时间】:2019-06-20 00:59:26 【问题描述】:

我正在创建一个客户注册页面,它将客户添加到我的 firebase 数据库中。注册后,应用程序应进入下一个活动,即谷歌地图。客户被添加到数据库中,但在移动到下一个活动时崩溃。这是我的代码:

SignupActivityCustomer.java:

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.Patterns;
import android.view.View;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.FirebaseDatabase;

public class SignupActivityCustomer extends AppCompatActivity implements View.OnClickListener 

    private EditText editTextName, editTextEmail, editTextPassword, editTextPhone;
    private ProgressBar progressBar;

    private FirebaseAuth mAuth;

    private static final String TAG = "SignupActivityCustomer";

    @Override
    protected void onCreate(Bundle savedInstanceState) 
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_signup_customer);

        editTextName = findViewById(R.id.edit_text_name);
        editTextEmail = findViewById(R.id.edit_text_email);
        editTextPassword = findViewById(R.id.edit_text_password);
        editTextPhone = findViewById(R.id.edit_text_phone);
        progressBar = findViewById(R.id.progressbar);
        progressBar.setVisibility(View.GONE);

        mAuth = FirebaseAuth.getInstance();

        findViewById(R.id.button_register).setOnClickListener(this);
    

    @Override
    protected void onStart() 
        super.onStart();

        if (mAuth.getCurrentUser() != null) 
            //handle the already login user
        
    

    private void registerUser() 
        final String name = editTextName.getText().toString().trim();
        final String email = editTextEmail.getText().toString().trim();
        String password = editTextPassword.getText().toString().trim();
        final String phone = editTextPhone.getText().toString().trim();

        if (name.isEmpty()) 
            editTextName.setError(getString(R.string.input_error_name));
            editTextName.requestFocus();
            return;
        

        if (email.isEmpty()) 
            editTextEmail.setError(getString(R.string.input_error_email));
            editTextEmail.requestFocus();
            return;
        

        if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) 
            editTextEmail.setError(getString(R.string.input_error_email_invalid));
            editTextEmail.requestFocus();
            return;
        

        if (password.isEmpty()) 
            editTextPassword.setError(getString(R.string.input_error_password));
            editTextPassword.requestFocus();
            return;
        

        if (password.length() < 6) 
            editTextPassword.setError(getString(R.string.input_error_password_length));
            editTextPassword.requestFocus();
            return;
        

        if (phone.isEmpty()) 
            editTextPhone.setError(getString(R.string.input_error_phone));
            editTextPhone.requestFocus();
            return;
        

        if (phone.length() != 10) 
            editTextPhone.setError(getString(R.string.input_error_phone_invalid));
            editTextPhone.requestFocus();
            return;
        


        progressBar.setVisibility(View.VISIBLE);
        mAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(new OnCompleteListener<AuthResult>() 
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) 
                        Log.d(TAG, "adding customer");
                        if (task.isSuccessful()) 

                            Customer user = new Customer(
                                    name,
                                    email,
                                    phone
                            );

                            FirebaseDatabase.getInstance().getReference("Customers")
                                    .child(FirebaseAuth.getInstance().getCurrentUser().getUid())
                                    .setValue(user).addOnCompleteListener(new OnCompleteListener<Void>() 
                                @Override
                                public void onComplete(@NonNull Task<Void> task) 
                                    progressBar.setVisibility(View.GONE);
                                    Log.d(TAG, "customer added");
                                    if (task.isSuccessful()) 
                                        startActivity(new Intent(SignupActivityCustomer.this, CustomerHome.class));
                                     else 
                                        //display a failure message
                                    
                                
                            );

                         else 
                            Toast.makeText(SignupActivityCustomer.this, task.getException().getMessage(), Toast.LENGTH_LONG).show();
                        
                    
                );

    

    @Override
    public void onClick(View v) 
        switch (v.getId()) 
            case R.id.button_register:
                registerUser();
                break;
        
    


Logcat error:

2019-01-26 11:29:10.843 4038-4038/com.example.julie.fyp D/SignupActivityCustomer: customer added
2019-01-26 11:29:11.669 1880-1959/? W/InputDispatcher: channel '4a251a2 com.example.julie.fyp/com.example.julie.fyp.SignupActivityCustomer (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
2019-01-26 11:29:11.669 1880-1959/? E/InputDispatcher: channel '4a251a2 com.example.julie.fyp/com.example.julie.fyp.SignupActivityCustomer (server)' ~ Channel is unrecoverably broken and will be disposed!
2019-01-26 11:29:11.719 1880-2523/? W/InputDispatcher: Attempted to unregister already unregistered input channel '4a251a2 com.example.julie.fyp/com.example.julie.fyp.SignupActivityCustomer (server)'

【问题讨论】:

【参考方案1】:

据我所知,Firebase 现在是异步工作的,因此它正在另一个线程上工作。

您可以尝试将startActivity 放入runOnUiThread(Runnable) 代码中

if (task.isSuccessful()) 
    runOnUiThread(new Runnable()
        public void run() 
            startActivity(new Intent(SignupActivityCustomer.this, CustomerHome.class));
        
    );
 else 
    //display a failure message

希望它有效

【讨论】:

以上是关于通道被不可恢复地破坏并将被处理的主要内容,如果未能解决你的问题,请参考以下文章

MSBuild 还原给出“请求被中止:无法创建 SSL/TLS 安全通道。”

洞穴勘测(bzoj 2049)

[SDOI2008]洞穴勘测

[SDOI2008]Cave 洞穴勘测

[SDOI 2008]Cave 洞穴勘测

[Sdoi2008]洞穴勘测——LCT