0

I am doing an e-commerce app, do I need to pass the AUTH information like id from Login activity -> Home Fragment -> product activity -> product details (when user add to favor list it will be based on the user id, add to firebase which is sub-collection under user list)

I try to pass the data from Login activity -> HomeFragement -> product ->details ->account

can I do like this getExtra from then put extra to(it will be like a middle man to pass data between them):

var docIDAuth = requireActivity().intent.getStringExtra("docIDFromLoginAuth")
var intent = Intent(requireActivity(), ProductDetails::class.java)
intent.putExtra("docIDFromLoginAuth", docIDAuth)
startActivity(intent)

or call it to pass to multiple activities/fragment in one times

var docIDAuth = requireActivity().intent.getStringExtra("docIDFromLoginAuth")
var intent = Intent(requireActivity(), Login::class.java)
intent.putExtra("docIDFromLoginAuth", docIDAuth)
startActivity(intent)
 
var intent = Intent(requireActivity(), HomeFragment::class.java)
intent.putExtra("docIDFromLoginAuth", docIDAuth)
startActivity(intent)

     var intent = Intent(requireActivity(), Prodcut::class.java)
intent.putExtra("docIDFromLoginAuth", docIDAuth)
startActivity(intent)
 
var intent = Intent(requireActivity(), ProductDetails::class.java)
intent.putExtra("docIDFromLoginAuth", docIDAuth)
startActivity(intent)

or should I use interface or ViewModel to do it?

Can u show the sample code to tell me how to implement it. I am new to this.

1
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
    – Community Bot
    Sep 12, 2021 at 7:02

1 Answer 1

0

I need to pass the AUTH information like id from Login activity -> Home Fragment -> product activity -> product details

There is no need to pass the UID from one activity to another. If your user is logged in, then you should simply use:

val uid = FirebaseAuth.getInstance().currentUser?.apply {
    Log.d("TAG", uid)
    //Add the product to favorites under the UID
}

In each activity/fragment is needed.

2
  • Did u mean I can direct call this "FirebaseAuth.getInstance()" function to get the user.uid because when the user log in, the user Info have store inside FirebaseAuth?Hence, I needed to call it In each activity/fragment
    – Cayden
    Sep 7, 2021 at 14:38
  • 1
    @user14748466 Yes.
    – Sam Chen
    Sep 7, 2021 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.