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.
-
1check this one: http://thedevelopersinfo.wordpress.com/2009/10/15/passing-data-between-activities-in-android/ – Vikas Patidar Feb 02 '11 at 11:40
-
If your utility class is passive you can make a library otherwise, its possible to have two packages in one app. – Reno Feb 02 '11 at 11:40
-
i have edited my answer. please have a look. – Dr. Rajesh Rolen Feb 02 '11 at 11:48
-
I achieved this using "Handler" class. Than you all for your help :) – Vidz Feb 22 '11 at 10:11
2 Answers
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

- 1
- 1

- 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