e.g. Activity 1 Button b = (Button)findViewbyId(R.id.button); // i want b.setOnClickListener in Activity2 Activity 2 b.setOnClickListener(this);
Asked
Active
Viewed 21 times
0
-
I don't think this is a good idea even if it is basically possible. What are you trying to achive by this approach? – Bö macht Blau Apr 04 '18 at 17:39
-
i want to get callback in another activity that button is clicked and want to perform some operation. Do u have any idea sir ? – Abdul Basit Apr 04 '18 at 17:42
-
But if you click a Button in one Activity then the other Activity may not even exist (can be destroyed e.g. if the device is low on memory) – Bö macht Blau Apr 04 '18 at 17:44
-
if i don't finish 1st activity and open second one then how it will work > – Abdul Basit Apr 04 '18 at 17:50
-
Then you should have the OnClickListener in the same Activity where the Button is. And then you take a look at [this post](https://stackoverflow.com/questions/3510649/how-to-pass-a-value-from-one-activity-to-another-in-android) – Bö macht Blau Apr 04 '18 at 17:53
-
No bro. is there any possibility to get button's callback in activity2. – Abdul Basit Apr 04 '18 at 17:57
-
None that I can recommend. – Bö macht Blau Apr 04 '18 at 17:58
-
For a callback like use case you may want to use this approach. https://developer.android.com/training/basics/intents/result.html – umuieme Apr 04 '18 at 18:24
-
You can use EventBus instead of callback between two activity. – ישו אוהב אותך Apr 05 '18 at 10:45