无法在firebase

时间:2017-11-20 19:04:20

标签: java android firebase

当我在写完姓名,姓氏并拍摄个人资料照片后登录Firebase时,我按下#34;完成注册"并启动用户帐户的活动以及除用户电子邮件地址外未显示的用户和个人资料图片的名称。但是,当我重新启动我的应用程序用户名和配置文件图片显示。我想在注册用户数据(姓名,姓名,个人资料图片)后显示姓名和个人资料图片。我该如何解决?

注册用户数据活动代码

 finishRegistration.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            final ProgressDialog loadData = ProgressDialog.show(RegisterUserInformation.this,"Sending data to Server", "Please wait", true,false);

            UserProfileChangeRequest request = new UserProfileChangeRequest.Builder()
                        .setDisplayName("" + name.getText().toString() + " " + lastname.getText().toString()).build();


            mUser.updateProfile(request);

            mStorageReference.child("Online Scheduler").child("Users").child("" + mUser.getUid()).child("Profile Picture").putFile(selectedImage)
                    .addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
                            @Override
                            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                               loadData.dismiss();
                            }
                        });




            HashMap<String, Object> userData = new HashMap<>();
            userData.put("Name", name.getText().toString());
            userData.put("Last name", lastname.getText().toString());
            userData.put("Email", mUser.getEmail());
            userData.put("UId", mUser.getUid());

            myRef.child("Online Scheduler").child("Users").child("" + mUser.getUid()).child("User Information").setValue(userData).addOnCompleteListener(new OnCompleteListener<Void>() {
                @Override
                public void onComplete(@NonNull Task<Void> task) {
                       loadData.dismiss();


                    Intent goToUserAccount = new Intent(getApplicationContext(),Account.class);
                       startActivity(goToUserAccount);
                }
            });
        }
    });

用户帐户活动代码

 if(mUser != null)
           {
               name.setText(mUser.getDisplayName());
               email.setText(mUser.getEmail());

               Log.d(logTag,"" + mUser.getDisplayName());
               Log.d(logTag, "" + mUser.getEmail());

               //Get profile picture for facebook authentication user.
               Glide.with(getApplicationContext()).load(mUser.getPhotoUrl()).listener(new RequestListener<Uri, GlideDrawable>() {
                   @Override
                   public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {
                       progressBar.setVisibility(View.INVISIBLE);
                       return false;
                   }

                   @Override
                   public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                       progressBar.setVisibility(View.INVISIBLE);
                       return false;
                   }
               }).into(avatar); // Get profile picture for facebook authentication user.

               //Get profile picture for email authentication user.
               sRef.child("Online Scheduler").child("Users").child("" + mUser.getUid()).child("Profile Picture")
                       .getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                   @Override
                   public void onSuccess(final Uri uri) {
                     Glide.with(getApplicationContext()).load(uri).listener(new RequestListener<Uri, GlideDrawable>() {
                         @Override
                         public boolean onException(Exception e, Uri model, Target<GlideDrawable> target, boolean isFirstResource) {

                             Log.d(logTag,"" + uri.toString());

                             progressBar.setVisibility(View.INVISIBLE);
                             return false;
                         }

                         @Override
                         public boolean onResourceReady(GlideDrawable resource, Uri model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {

                             Log.d(logTag,"" + uri.toString());
                             progressBar.setVisibility(View.INVISIBLE);
                             return false;
                         }
                     }).into(avatar);
                   }
               }); //Get profile picture for email authentication user.
           }

1 个答案:

答案 0 :(得分:0)

您需要向firesdatabase添加一些EventListener,以便您可以收听更改;每当更改firebasedatabase时,都会调用onDataChange回调方法。 例; EventListener,ChildEventListener,ValueEventListener

mStorageReference.child("Online 
Scheduler").child("Users").child("Uid")
.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {

    }

    @Override
    public void onCancelled(DatabaseError databaseError) 
    }
 });

https://firebase.google.com/docs/database/android/read-and-write#listen_for_value_events https://firebase.google.com/docs/database/android/lists-of-data#child-events https://firebase.google.com/docs/database/android/lists-of-data#listen_for_value_events