2

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.

Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178
Vidz
  • 406
  • 2
  • 4
  • 16

2 Answers2

1
jmj
  • 237,923
  • 42
  • 401
  • 438
1

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

Community
  • 1
  • 1
Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178
  • Thanks for your response. In my case, I have a utility class having methods. I want to return/pass output data asynchornously to the application which had called my methods. – Vidz Feb 03 '11 at 05:45
  • @Vidhya: it would be more helpful if you could paste related code. so that people can see exact situation and provide you better solution . – Dr. Rajesh Rolen Feb 03 '11 at 06:15
  • Could you pls refer to the below post? http://stackoverflow.com/questions/4883079/usage-of-sendbroadcast – Vidz Feb 03 '11 at 08:46