赞
踩
有一个场景是在子线程中调用Fragment的getString()方法(如在Retrofit回调中、handler中等),而此时,有可能app被内存回收了,那么此时fragment已经detach了,就会发生这个异常。
解决方法:
1. 如果在Fragment里,并且是在子线程中调用getString()方法,则需要加一个isAdded()判断,这是一个Fragment类中的方法。
if(isAdded){
mTextView.setText(getString(R.string.something));
}
2. 尽可能使用application的context来getString()。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。