In Activity A there is a variable with a value. From here user goes to Activity B then to Activity C. Here he does something that changes that variable in Activity A. So when user goes BACK from Activity C to Activity B to Activity A, that value must be changed. To make things simpler, all I want is to show a Toast message when user goes back (by clicking the BACK button) to Activity A without having to launch it again.
By changing a variable I mean when Activity A is displayed to the user it needs to know that something happened in Activity C that makes Activity A change the variable (by running a script or something).
The problem is that the Toast message is displayed when I launch Activity A, but it's not when I go back from Activity C to Activity B to Activity A.
Here is what I tried:
OnCustomEventListener.java
public interface OnCustomEventListener {
public void onEvent();
}
Activity A:
@Override
public void onCreate(Bundle savedInstanceState) {
Activity_YourProfile actv_yourprofile = new Activity_YourProfile();
//endless lines of code
actv_yourprofile.setCustomEventListener(new OnCustomEventListener(){
public void onEvent(){
Toast.makeText(Activity_MyProfile.this, "performed", Toast.LENGTH_SHORT).show();
}
});
}
Activity B:
Nothing special just an intent that takes user to Activity C.
Activity C:
private OnCustomEventListener mListener;
@Override
public void onCreate(Bundle savedInstanceState) {
//code
setCustomEventListener(mListener); //calling callback e.g. on Btn click
}
public void setCustomEventListener(OnCustomEventListener eventListener) {
this.mListener=eventListener;
if(this.mListener!=null){
this.mListener.onEvent();
}
}
Based on the solution of Mocialov Boris.