Android Retreiving data from an activity and displaying it to a fragment with firebase

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Android Retreiving data from an activity and displaying it to a fragment with firebase



I have implemented a feature where the use can click on a button to open a new activity and change their user status. I have it so that when the user presses the button it updates the firebase database but when the user goes back to the previous activity firebase does not retrieve the new data. I am attempting to use a bundle and pass the data from the change status activity to the profile fragment and then update the user status with the fresh one that was brought over.


Bundle bundle = new Bundle();
String myStatus = status;
bundle.putString("status", myStatus);
ProfileFragment fragInfo = new ProfileFragment();
fragInfo.setArguments(bundle);



And then on the fragment that displays this


public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState)



View view = inflater.inflate(R.layout.fragment_profile, container, false);

CircleImageView displayProfilePicture = view.findViewById(R.id.settings_profile_picture);
final TextView mName = view.findViewById(R.id.profile_user_name);
final TextView mStatus = view.findViewById(R.id.profile_user_status);
final Button mChangeStatusBtn = view.findViewById(R.id.settings_change_status_btn);

mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();

String current_uid = Objects.requireNonNull(mCurrentUser).getUid();

mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(current_uid);


// attempting to bring the data over
Bundle bundle = this.getArguments();
String myValue = bundle.getString("status");


mChangeStatusBtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)
Intent changeStatusIntent = new Intent(getActivity(), ChangeStatus.class);
startActivity(changeStatusIntent);

);


mUserDatabase.addValueEventListener(new ValueEventListener()
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot)
String keys=dataSnapshot.getKey();
String profileDisplayName=dataSnapshot.child("name").getValue().toString();
String profileStatus= dataSnapshot.child("status").getKey();

mName.setText(profileDisplayName);
mStatus.setText(profileStatus);


@Override
public void onCancelled(@NonNull DatabaseError databaseError)



);

mChangeStatusBtn.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View view)



String status_value = mStatus.getText().toString();

Intent statusIntent = new Intent(getActivity(), ChangeStatus.class);
statusIntent.putExtra("status_value", status_value);
startActivity(statusIntent);

);
return view;
}









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard