I want to start one of my existing activities and force the activity to call a specific method after it starts. Is this possible?
Can I define a method that should be called after creating the activity inside my Intent
?
For example, something like:
Intent intent = new Intent(this, com.app.max.Home.class.myMethod);
Hello You can't call a particular method from intent but alternately you can use a service from intent and your requirement will be done.
and in MyService.class
}
and register this service in your manifest file like this
No, I don't think you can have something like this:
but you can do this:
and then in the called activity (where you need to start the method), you can take the intent and decide which method to call like this:
You question seems interesting, but there is no way you can do it using
Intent
. You have to understand that when you start an activity, it goes through a life cycle which is :onCreate()
->onStart()
->OnResume()
. So what you can do is start that method fromonResume()
like this:I'm just trying to help,give me some more information about your problem if this approach does not solve your problem.
I solve this issue by using
onCreate
instead ofonNewIntent
.Activity A:
com.app.max.Home Activity:
Hope this solution solve your problem