1

I am developing an android library named samplelib.jar which contains a method executeFlow() in a seperate class CallMyFlow. I added this library in my main project and called CallMyFlow.executeFlow() at the time of OnCreate() which works perfectly.

But i need the executeFlow() method should run automatically without calling it in OnCreate(). I want to simply add that jar into my project. And the library itself want to find the OnCreate() is happening and it should automatically call the executeFlow() method.

I need not want to add any extra code into my main project(i.e) calling the method in OnCreate(), or extending any custom class in library. Is it possible? I tried it, but could not get the result. Any ideas are welcome.

Chris
  • 1,311
  • 2
  • 15
  • 37
  • Just curiosity, why you don't want to call CallMyFlow.executeFlow() and still want the result from it. – Rasel Oct 05 '12 at 05:53
  • 1
    I don't think it's possible to somehow inject your own behavior into android without having the user subclass from some base activity class which you define. If so there would be a lot of projects doing that (like roboguice, easytracker/google analytics, etc). – Matt Wolfe Oct 05 '12 at 05:59

2 Answers2

1

No, that is not possible. To have your library do something you need to call some function, or instantiate some object from your library.

I'm not sure why you want this behaviour, but if you want to have some code executed before you create an object from your library, take a look at static blocks. Notice however, static blocks also need their class to be used before they are executed: When does static class initialization happen?

Community
  • 1
  • 1
1

According to android SDK i hope it is not possible.

Prabhu
  • 590
  • 2
  • 9
  • 22