Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass handler using intent

there are 2 activity A and Screen in A Activity , i made handler and want to pass it to screen activity

Handler error_handler = new Handler() {
public void handleMessage(Message msg) {
}};

Intent loginButton_intent = new Intent(A.this, Screen.class);
loginButton_intent.putExtra("URL", URL);
loginButton_intent.putExtra("IP_Addres", dvr_login_data.IP_Addres);
loginButton_intent.("HAND", error_handler); <- but this code is error 

how can i pass handler ? plz warm-answer

like image 693
n2v2rda2 Avatar asked Dec 29 '22 07:12

n2v2rda2


2 Answers

still looking for an answer? I had the same problem and found this question through google, so others might show up as well.

Anyways, I found my solution to the problem of using a handler between a service and an activity in the Android documentation. Just look at the Remote Messenger Service Sample right here: Remote Messenger Service Sample

Basically they are using a messenger as client interface for a local handler in the service.

Regards, Michael

like image 141
michael Avatar answered Jan 15 '23 05:01

michael


Well, to keep it short, you can't...Handler implements neithor Serializable nor Parcelable so it cannot be put as an extra...The Object Transported using Intents must follow eithor of those protocols.

Speculation I suppose, there's an alternative that would involve creating a Service to act as a middle man. But that'll require some testing.

like image 40
st0le Avatar answered Jan 15 '23 04:01

st0le