Tejas Soni
Tejas Soni

Reputation: 37

Passing function from one activity to another via Broadcasts

I want to pass a function from one activity to another using Broadcasts. Like we can pass Strings and int by putExtra, Is there a way I can pass a whole function? I know there are other ways to do this, but I need to do this with the help of broadcasts. Any help?

Ex:

void myFunc(){ /* foo */ }

Can I use myFunc in some other activity via broadcast? I don't mind declaring the function again in the new activity as long as I get data from broadcast.

Upvotes: 0

Views: 92

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006744

Is there a way I can pass a whole function?

No, sorry.

Can I use myFunc in some other activity via broadcast?

No, sorry.

Alternatives:

  • Use one activity rather than two

  • Have both activities work with some other object that is outside each of those activities (e.g., a singleton serving as a repository)

Upvotes: 1

Related Questions