Is there any possible way to call a method at the time when call the intent activity. I want to display only particular method when i switch over from one activity to another using intent call.
Most commonly, ACTION_SEND action sends URL of build-in Browser app. While sharing the data, Intent call createChooser() method which takes Intent object and specify the title of the chooser dialog. Intent. createChooser() method allows to display the chooser.
Using putExtra() We can start adding data into the Intent object, we use the method defined in the Intent class putExtra() or putExtras() to store certain data as a key value pair or Bundle data object. These key-value pairs are known as Extras in the sense we are talking about Intents.
Android App Development for Beginners An intent is to perform an action on the screen. It is mostly used to start activity, send broadcast receiver,start services and send message between two activities.
The Best Answer is You can use startActivityForResult or you can pass the values from one activity to another using intents and do what is required.
Use the extras
bundle in the Intent
.
Intent i = new Intent(...);
i.putExtra("your_condition", int_condition);
Then on onCreate of the Intent
int_condition=getIntent.getIntExtra("your_condition");
Now you can use this
if(int_condition==0)
{
//Call the method
}
else
{
//method you want
}
Again there is another option for you as you can pass the method name as a parameter in your Intent
, assumes that you are sending mathod_name
as an extra
to the Bundle
String method_name=getIntent.getIntExtra("method_name");
Class<?> c = Class.forName("class name");
Method method = c.getDeclaredMethod (method_name, parameterTypes)
method.invoke (objectToInvokeOn, params)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With