我有getInstance
和同一个类中的构造函数,但我不确定我在哪里放置Init
方法。
public class UploadService {
private Eng mEng;
private Context mContext;
private static UploadService INSTANCE;
private String appDir;
public static UploadService getInstance(Context context) {
if (null == INSTANCE) {
INSTANCE = new UploadService(context);
}
return INSTANCE;
}
public UploadService(Context context) {
this.mContext = context;
appDir=V8Utils.getAppDir(context);
}
public void init(Context cxt) {
mEng = new Eng(cxt);
mEng.init(appDir);
}
}
答案 0 :(得分:2)
我会
init()
标记为私有方法。UploadService
对象初始化Context
对象的状态。我的意思是:
public UploadService(Context context) {
this.mContext = context;
appDir=V8Utils.getAppDir(context);
init(context);
}
private void init(Context cxt) {
mEng = new Eng(cxt);
mEng.init(appDir);
}