0

The problem I have with Authentication is that it takes up so much time and returns the result maybe after 10 minutes. I ended up skipping the authentication most of the time in my app using the manifest file.

With firebase firestore I am unable to get any data back and the log with Firebase filtered gives me below.

2022-11-03 05:30:59.981 453-473/? W/TransactionTracing: Could not find layer id -1 2022-11-03 05:31:00.114 453-473/? W/TransactionTracing: Could not find layer handle 0x7f187c234bf0

Kindly refer to the below codes and please let me know if I've done any wrong implementations.

Am I using the correct imports?

    import android.util.Log;
    import com.example.xstudies.static_data.dataString;
    import com.google.android.gms.tasks.OnCompleteListener;
    import com.google.android.gms.tasks.Task;
    import com.google.firebase.firestore.CollectionReference;
    import com.google.firebase.firestore.FirebaseFirestore;
    import com.google.firebase.firestore.QueryDocumentSnapshot;
    import com.google.firebase.firestore.QuerySnapshot;

FirebaseAuth mAuth;
FirebaseFirestore db;
ProgressBar progressBar;

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

    mAuth = FirebaseAuth.getInstance();
   db = FirebaseFirestore.getInstance();

 private void logIn() {

    String userEmail = email.getText().toString();
    String userPassword = password.getText().toString();
    Toast.makeText(this, "now trying ", Toast.LENGTH_SHORT).show();
    if(!userEmail.isEmpty() && !userPassword.isEmpty()){

    mAuth.signInWithEmailAndPassword(userEmail,userPassword)
            .addOnCompleteListener(new OnCompleteListener<AuthResult>(){
                @Override
                public void onComplete(@NonNull Task<AuthResult> task){
                    if(task.isSuccessful()){
 //                            progressBar.setVisibility(View.GONE);
 //                             Toast.makeText(LoginActivity.this,"Login Successfull", 
   Toast.LENGTH_SHORT).show();
                        startActivity(new Intent(LoginActivity.this, MainActivity.class));
                        finish();
                    }
                    else{

                        Toast.makeText(LoginActivity.this,"Error"+ task.isSuccessful(), 
Toast.LENGTH_SHORT).show();
                        progressBar.setVisibility(View.GONE);
                    }
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    
  
 Toast.makeText(LoginActivity.this,"error"+e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
                }
                  })
            .addOnCanceledListener(new OnCanceledListener(){
                @Override
                public void onCanceled() {
                        
   Toast.makeText(LoginActivity.this,"Canceled",Toast.LENGTH_SHORT).show();
                }
            });
 }
  }


     //for the Firestore query please refer to below
        db.collection
                        ("Products").whereEqualTo("isFeatured",true ).get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()) {
                            for (QueryDocumentSnapshot document : task.getResult()) {
   //                      Log.d(TAG, document.getId() + " => " + document.getData());
                                MyProducts popularItem = document.toObject(MyProducts.class);
  //                                    Toast.makeText(getActivity(), popularItem.getName(), 
  Toast.LENGTH_SHORT).show();
                                AbstractCollection<MyProducts> popularModelList = null;
                                popularModelList.add(popularItem);
                                featuredAdapter.notifyDataSetChanged();
   //                           Toast.makeText(getActivity(), (String) 
    document.get("name"),Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(getActivity(), "Error" + task.getException(), 
  Toast.LENGTH_SHORT).show();
                        }
                    }
                });
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Me Compu
  • 25
  • 6
  • How many documents does `db.collection ("Products").whereEqualTo("isFeatured",true )` return? – Alex Mamo Nov 03 '22 at 11:00
  • Hi ALex, the querry is not returning anything so my UI is empty and unable to show anything. Do I need to revise anything from this line? Thanks – Me Compu Nov 04 '22 at 01:29
  • The query returns documents but those documents aren't displayed in the UI? Or the query doesn't return anything at all? – Alex Mamo Nov 04 '22 at 06:23
  • Hi Alex I can only actually get it to work using an installed apk on my phone but I wonder why when I use the emulator I can't seem to connect to Firebase services. Ill try to update some dependecies but do you know any specifics solution to this or which service in my gradle dependenices or any internal code or dependency need to be added to get this to work on the android studio emulator. Thanks bro. – Me Compu Nov 06 '22 at 11:39
  • Be sure you're connected to the internet. – Alex Mamo Nov 06 '22 at 12:16
  • Hi Alex yes bro connected to the internet. i also added the lines required in the manifest file . The registration to the auth service seems t be working fine but Firebase Realtime Database or Firestore is not working but when connected the real phone using apk or usb debugging the registrration method and also storing to Firebase Realtime and Firestore is working. I also updated the dependencies in gradle app and project google servies . – Me Compu Nov 06 '22 at 12:50
  • Can you please try to upgrade or downgrade the version for android studio emulator and test? You can check issue discussed in stackoverflow URL https://stackoverflow.com/questions/73370728/firebase-doesnt-work-on-android-studio-emulator/73387871#73387871 for the details. – Vaidehi Jamankar Nov 16 '22 at 12:33

0 Answers0