开发者

Passing data from one class to another class

开发者_如何学编程

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜