FirebaseAuthentication

FirebaseAuthentication

我正在发布并检索需要Firebase身份验证的应用程序。我知道Firebase使用异步方法,以免在主线程上传递其功能。但是,除了FirebaseAuthenticationFireDatabase.getInstance().getReference().child()之外,其他所有东西似乎都在起作用。这造成很多困难。

我的启动器页面 Activity 。

 package com.gmail.peeman34.eglisaofficial;


//private Button eglisasignupbutton;
//Handler handler = null;

public EGLISA_OFFICIAL() {
    super();
  }
//}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.eglisa_official);


    Thread timer = new Thread() {

        @Override
        public void run() {

            try {
                sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            Intent openStartingPoint = new Intent(EGLISA_OFFICIAL.this, BRIDGE.class);
            startActivity(openStartingPoint);
            finish();

        }
    };
    timer.start();
 }

 }

这是我的页面,为您提供登录或注册按钮。在这种情况下,请注册:
package com.gmail.peeman34.eglisaofficial;

public class BRIDGE extends AppCompatActivity {
private Button signituphere;
private Button signitinhere;
Handler firsthandler = new Handler();
Thread mythread;
Handler handler;
Intent peethread;
public BRIDGE() {
    super();
  }

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.bridge);


    signituphere = (Button) findViewById(R.id.signituphere);


    Button signitinhere = (Button) findViewById(R.id.signituphere);

        Thread mythread = new Thread(new Mythread());
      mythread.start();


   }

public void startLogin(View view){
       handler = new Handler();
    handler.post(new Runnable() {
        @Override
        public void run() {
             peethread = new Intent(BRIDGE.this, ActivityMaiin.class);

            startActivity(peethread);

        }
     });


    }


class Mythread extends Thread {


    private Handler handler;

    public Mythread() {

     }

    @Override
    public void run() {


        try {


            sleep(10000);

            Looper.prepare();
            handler = new Handler();
            Looper.loop();


        } catch (InterruptedException e) {
            e.printStackTrace();
        }




    }



    }

    }

这是“注册”页面,该页面不起作用,因为FirebaseAuthenticationFireDatabaseReference().getInstance().getReference().child()不断使我的应用加载并崩溃。
 package com.gmail.peeman34.eglisaofficial;

 import android.app.ProgressDialog;
 import android.content.Intent;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 import android.text.TextUtils;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ImageButton;
 import android.widget.Toast;

 import com.google.android.gms.appdatasearch.RegisterSectionInfo;
 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.DatabaseReference;
 import com.google.firebase.database.FirebaseDatabase;


import static com.gmail.peeman34.eglisaofficial.R.string.view;

/**
 * Created by pee on 6/1/2016.
*/

public class ActivityMaiin extends AppCompatActivity {


private EditText Namefield;
private EditText Emailfied;
private EditText Passwordfield;
private Button mRegistration;
private ProgressDialog mProgress;
ImageButton Loginthebutton;
Intent AccountSetup;

Handler africanhandler;
Handler thefirsthandler;
Thread firstthread;
Thread secondthread;

private FirebaseAuth mAuth;

private DatabaseReference mDatabase;


public ActivityMaiin() {
    super();
}


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainactivity22);

    Namefield = (EditText) findViewById(R.id.username);
    Emailfied = (EditText) findViewById(R.id.email);
    Passwordfield = (EditText) findViewById(R.id.password);

    mAuth = FirebaseAuth.getInstance();
    mDatabase=FirebaseDatabase.getInstance().getReference().child("Users");


    mRegistration = (Button) findViewById(R.id.signupbutton);
    Loginthebutton = (ImageButton) findViewById(R.id.loginthebutton);
    mProgress = new ProgressDialog(this);


     firstthread = new Thread(new Myfirstthread());

    firstthread.start();

    secondthread.start();





    mRegistration.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

      try {

          startRegister();



      }catch (Exception e){

      }
        }
    });






}







public void  startaccountsetup() {

   thefirsthandler = new Handler();

   thefirsthandler.post(new Runnable() {


       @Override
       public void run() {


           Intent setuptheaccount = new Intent(ActivityMaiin.this,
            ACCOUNTSETUP.class);
           startActivity(setuptheaccount);


       }





   });

}
               class  Myfirstthread extends Thread{
                       public Myfirstthread() {
                           super();
                       }


                       @Override
                       public void run() {
                          /* try {
                               sleep(10000);

                           } catch (InterruptedException e) {
                               e.printStackTrace();


                           }*/


                           Looper.prepare();

                            Looper.loop();
                       }
                   }









           public  void startRegister() throws InterruptedException {


           final String name = Namefield.getText().toString().trim();
           String email = Emailfied.getText().toString().trim();
        String password = Passwordfield.getText().toString().trim();

               if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email)
          && !TextUtils.isEmpty(password)) {
            mProgress.setMessage("Signing up");
            mProgress.show();


            try {

                mAuth.createUserWithEmailAndPassword(email,
      password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        if (task.isSuccessful()) {

                            String user_id = mAuth.getCurrentUser().getUid();
                            DatabaseReference current_user_db = mDatabase.child(user_id);

                            current_user_db.child("name").setValue(name);
                            current_user_db.child("image").setValue("default");

                            mProgress.dismiss();



                            startaccountsetup();
                         }


                    }

                });
            } catch (Exception e) {

            }

        }


           }

}

在某种程度上,这是我的堆栈跟踪。只需忘记处理程序即可。我担心Firebase实例。处理程序工作正常。由于我一直在尝试和尝试错误,因此它们安排有误。
FATAL EXCEPTION: main
                                                                               Process: com.gmail.peeman34.eglisaofficial, PID: 23807
                                                                               java.lang.IncompatibleClassChangeError: com.google.firebase.zza
                                                                                   at com.google.android.gms.internal.zzbiu.<init>(Unknown Source)
                                                                                   at com.google.android.gms.internal.zzbjc.zza(Unknown Source)
                                                                                   at com.google.firebase.auth.FirebaseAuth.zzb(Unknown Source)
                                                                                   at com.google.firebase.auth.FirebaseAuth.<init>(Unknown Source)
                                                                                   at com.google.android.gms.internal.zzbkg.<init>(Unknown Source)
                                                                                   at com.google.firebase.auth.FirebaseAuth.zzd(Unknown Source)
                                                                                   at com.google.firebase.auth.FirebaseAuth.zzc(Unknown Source)
                                                                                   at com.google.firebase.auth.FirebaseAuth.getInstance(Unknown Source)
                                                                                   at com.gmail.peeman34.eglisaofficial.ActivityMaiin.onCreate(ActivityMaiin.java:67)
                                                                                   at android.app.Activity.performCreate(Activity.java:6237)
                                                                                   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                   at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                   at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                   at android.os.Looper.loop(Looper.java:148)
                                                                                   at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                   at java.lang.reflect.Method.invoke(Native Method)
                                                                                   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

最佳答案

找出问题所在,在gradle文件中,无论存储,数据库还是身份验证,我都没有firebaseui。我也意识到,firebase依赖关系,firebaseui和play服务之间存在兼容性问题。也许这可以帮助https://github.com/firebase/FirebaseUI-Android

关于android - FirebaseAuthentication.getInstance()导致应用崩溃,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43701781/

10-11 20:47