开发过程遇到一个问题,app在低内存或者其他原因被系统杀死的情况下,从后台恢复会出现空白页面或者崩溃的问题,具体app恢复机制参考这篇文章:点击打开链接
但是我的问题不仅仅是这样,实际中我遇到重启后遇到java.lang.NoClassDefFoundError,代码提示错误在以下片段:
private static class SingletonContainer {
private static ThreadPool mSingleInstance = new ThreadPool();
}
//这里用经典单列模式在app restart后会报错NoClassDefFoundError,原因不明
public static ThreadPool getInstance() {
return SingletonContainer.mSingleInstance;
}
但是 SingletonContainer.mSingleInstance为什么会找不到呢?百思不得其解,参考了以下文章:怎么解决java.lang.NoClassDefFoundError错误,但是依然找不到问题所在,于是换了一种单列模式的写法:
private volatile static ThreadPool instance = null;
public static ThreadPool getInstance() {
if (instance == null) {
synchronized (ThreadPool.class) {
if (instance == null) {
instance = new ThreadPool();
}
}
}
return instance;
}
这样居然就不报错了,虽然解决了问题,但是依然没有找到问题所在,先记录下来以后慢慢研究