0

Every time I want to make my fragment call it's onStart() or onResume(), I do the the next :

 getFragmentManager().beginTransaction().replace(R.id.containero1, new Massenger_frag(conversationID)).addToBackStack(null).commit(); 

is this good for the performance, is there another way to tell the fragment the new information arrived, and it must refresh its UI.

2
  • What do you mean "from another activity"? What is the point of refreshing a fragment of an activity the user cannot see? Commented Dec 31, 2013 at 17:14
  • the new information arraived to main activity, and I want the Fragment to "Know" about that, so I put the info in a variable and call the fragment to be visible, a in the code above, but when the fragment is visible and new info arrived to the main activity,I dont know how to refresh the fragment so I call it another time by the code above... Commented Dec 31, 2013 at 17:20

3 Answers 3

1

You can keep a reference to a "Massenger_frag" object that was used when doing the fragment replacement. You can also define a method "refresh" in your "Massenger_frag" class and call it from that instance variable. onStart()/onResume() from your fragment would also call the same refresh method to avoid code duplication.

What you are currently doing is not fast and adds a significant overhead as the new fragment is constructed every time and the old one gets deallocated.

Sign up to request clarification or add additional context in comments.

Comments

1

the solution is simple: I just use BroadCast sender and receiver, and send the information throw Activity A to Activity B, the Activity B in its onReceive() call a function that refresh its content!

Comments

0

Use interface and create custom EventListeners. Check an example here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.