I am developing a utility class in Android 2.2 exposing various methods to Application. Application can import my jar file(utility class) to invoke methods defined in utility class. Can somebody tell me how to pass/return data to application class from my utility class. Note: utility class and application class is kept under different packages.
- Passing Information to a Method or a Constructor
If you wants to use class of any other package in your current class then you will have to import that package in your class and then create object of its class and call its function.
http://leepoint.net/notes-java/language/10basics/import.html
EDIT: i found a same type of question : Using utility classes in the android programming
It heavily depends on what kind of utility you're referring to. There are
1) utility classes that implement static methods. In that case you just call them directly using class name
2) utility classes methods that are not static - requires creating and possibly initializing an instance of that class. Then the instance is used to call those methods.
3) utility classes that can be accessed thru Context. then you can call getApplicationContext() and then you can get access to the utility classes
精彩评论