在Android编程使用的工具类 [英] Using utility classes in the android programming

查看:94
本文介绍了在Android编程使用的工具类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的实用工具类与需求略有疑问的一点想法。

I have a little idea of the Utility Classes with a slight doubt on demand.

如果我使用一个实用工具类在我的应用程序,而不是使用这个类在我的主要的活动我一定要创建一个类的对象,或者我可以直接导入这个类在我的主要活动?

If I use a Utility class in my Application than to use that class in my main Activity do I have to create the object of that class or I can directly Import that class in my main activity?

我很抱歉,如果我不是一个明显的感觉。

I am Sorry if I am not making a clear sense.

在概括地说,我要的是明确的是,基本上我怎么能在我的主要活动使用的工具类?

In the nutshell, all I want to be clear about is that basically how can I use the utility class in my Main Activity?

谢谢, 大卫

推荐答案

这在很大程度上取决于你指的是什么样的效用。有

It heavily depends on what kind of utility you're referring to. There are

1)实现静态方法的实用工具类。在这种情况下,你只叫他们直接使用类名

1) utility classes that implement static methods. In that case you just call them directly using class name

2)的实用工具类方法是不是静态的 - 需要创建和可能初始化这个类的一个实例。然后实例用于调用这些方法。

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),可以通进行访问的工具类上下文。那么你可以调用<一个href="http://developer.android.com/reference/android/content/Context.html#getApplicationContext%28%29"相对=nofollow> getApplicationContext()然后你就可以 GET 进入实用工具类

3) utility classes that can be accessed thru Context. then you can call getApplicationContext() and then you can get access to the utility classes

这篇关于在Android编程使用的工具类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆