Changing text from another activity Changing text from another activity android android

Changing text from another activity


You should use Android Architecture Components :

You can create a ViewModel containing LiveData of your data object (LiveData<String> in case you want to change only text).

When you will change your live data object from one Activity or Fragment all other Activities and Fragments observing for this live data object will get notified.

Official API doc has complete example with description.


Make a public method in your TabActivity that sets the TextView's text, then call getParent() from the child activity, cast it to your TabActivity class, then call that public method.


You could try implementing a handler for the parent Tab which does the job. Pass the text in a message object from each of your respective tabs. To be safe, make changes within the handler inside a runOnUI block