有个需求,在适当的时候,弹出一个Dialog,请求用户输入签名。
如果不使用单实例,只需要将mDlgSignElectron=null,就能够释放这个对象了。
使用单实例,防止弹出多个Dialog。但同时带来的一个问题,当用户输入签名退出Dialog,这个单实例的对象一直驻留在内存里,如何释放呢?
//调用
AvcSignElectronDialog mDlgSignElectron;
mDlgSignElectron = AvcSignElectronDialog.getInstance(LoginActivity.this, R.style.SignElectronDialogTheme);
mDlgSignElectron.show();
//单实例类
public class AvcSignElectronDialog extends Dialog {
private static AvcSignElectronDialog mSingleton = null;
public static synchronized AvcSignElectronDialog getInstance(Context context, int theme) {
if (mSingleton == null) {
mSingleton = new AvcSignElectronDialog(context, theme);
}
return mSingleton;
}
private AvcSignElectronDialog(Context context, int theme) {
super(context, theme);
this.mContext = context;
}
}
------解决思路----------------------
我意思是,你用的时候要getInstance,不用的时候要releaseInstance
这样计数器就有增有减了。