android中变量的全局声明

suj*_*jay 5 java android android-2.2-froyo

我是android开发新手,我通过SAX解析器解析xml文件并将解析后的数据存储到string.Now我需要在另一个类中使用该字符串,所以我需要知道如何在新类中调用该解析器.提前致谢

Som*_*ere 9

我总是创建一个包含所有全局变量的类,并将其命名为"Constants.java"

final public class Constants//final to prevent instantiation
{
    public static final String SOME_STRING = "0.04";
    public static final int SOME_NUMBER = 5;
    public static final float METERS_PER_MILE = 1609.344f;

    //private constructor to prevent instantiation/inheritance
    private Constants()
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

要在您的代码中使用其中一个,请务必导入该类并使用:

Constants.SOME_NUMBER