I think, you should create a separate class that you will share between your activities A, B and C. The class should has a field, which will store text for your TextView in activity A. And there is a good variant to use Observer pattern (rxJava or custom decision).
Example:
SharedStateModel is used to save state for ActivityA.
That decision is not very clear, because it breaks dependency inversion rule so I recommend you to use Dagger 2 to inject SharedStateModel into ActivityA and ActivityC and manage its component's lifecycle like I describe in comments to SharedStateModeClass.
/*
Let's make that state-class a local singleton - you create it in onCreate of ActivityA and
further it can be destroyed in onDestroy of ActivityA.
*/
public class SharedStateModel {
private PublishSubject<String> stateListener = PublishSubject.create();
private String viewState;
private static SharedStateModel instance;
private SharedStateModel() {
}
public void setViewState(String viewState) {
this.viewState = viewState;
stateListener.onNext(viewState);
}
public PublishSubject<String> getStateListener() {
return stateListener;
}
public void destroyViewState() {
instance = null;
}
public static SharedStateModel getInstance() {
if (instance != null) {
return instance;
} else {
instance = new SharedStateModel();
return instance;
}
}
}
public class ActivityA extends AppCompatActivity {
@BindView(R.id.textView)
private TextView textView;
private SharedStateModel sharedStateModel;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
sharedStateModel = SharedStateModel.getInstance();
sharedStateModel.getStateListener().subscribe(
textViewState -> textView.setText(textViewState));
}
@Override
protected void onDestroy() {
super.onDestroy();
sharedStateModel.destroyViewState();
}
}
public class ActivityC extends AppCompatActivity {
@BindView(R.id.button)
private Button button;
/*
Let's assume that you want to send a message from EditText in ActivityC
*/
@BindView(R.id.editText)
private EditText editText;
private SharedStateModel sharedStateModel;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
sharedStateModel = SharedStateModel.getInstance();
button.setOnClickListener(view -> sharedStateModel.setViewState(
String.valueOf(editText.getText().toString())));
}
}
And I want to recommend you good guides from Eugene Matsyuk if you want to learn Dagger 2.