I have trouble to update the UI in activity when handler has called in other class. Below is the code that I created.
Activity A
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_A);
Handler handler = new Handler(); //Here is where the handler is start, other class will update the Handler message.
......
}
Activity B
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_B);
......
}
//Just a dummy function called when handler is triggered
private void onChange(){
TextView tv_status = findViewById(R.id.status);
tv_status.setText("Complete");
}
Class Handler
public Handler {
public Handler(){
Handler handler = new Handler(){
public void HandleMessage(Message msg){
switch (msg.what) {
case 1:
break;
case 2:
//should trigger to update the TextView in Activity B here
break;
}
}
};
.......
}
}
Activity A as main where the Handler is called to start the Handler, Activity B is just update the UI triggered by Handler.