No, it's not possible to do this. And (from comments) no, it's not possible to "click" a button from a separate Activity
. What you can do, however, is this:
// Calling code:
intent.putExtra(getPackageName() + ".click_me", R.id.your_button); // getPackageName() is for best practices
startActivity(intent);
// In your Activity:
Intent intent = getIntent(); // Get the Intent we used to launch this
int buttonToClick = intent.getIntExtra(getPackageName() + ".click_me", 0); // Get the integer
if (buttonToClick != 0) { // If it's 0, we didn't specify it
View toClick = findViewById(buttonToClick); // Find the View
if (toClick != null && toClick instanceof Button) { // If the View exists, and is a Button..
((Button) toClick).performClick(); // ..then click it
}
}
You provide the Intent
that starts the Activity
with an integer. This integer represents a View
(more specifically, a Button
). Once the Activity
receives it, it finds the matching View
, checks if its a Button
, then performs a click action on it.
This way, you're just passing the integer ID of an item to click, and your opened Activity
just handles the rest.