我正在使用Android注释。有一个进度对话框,但是当我旋转屏幕(陆地到港口)时。进度对话框解除并在log cat中显示这些错误。
活动com.example.progressdialog.AnnotationProgressDialogActivity_泄漏了最初添加的窗口com.android.internal.policy.impl.PhoneWindow$DecorView@40661c20
android.view.WindowLeaked:Activity com.example.progressdialog.AnnotationProgressDialogActivity_泄漏了最初添加的窗口com.android.internal.policy.impl.PhoneWindow$DecorView@40661c20
这是我的代码: -
@EActivity(R.layout.main)
public class AnnotationProgressDialogActivity extends Activity
{
@NonConfigurationInstance
ProgressDialog pd ;
@NonConfigurationInstance
@Bean
BackgroundTask bgt;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
}
@Click
public void loginButton()
{
pd = ProgressDialog.show(this,"Login", "Loading please wait.....");
bgt.backGroundMethod();
}
public void dismissDialog()
{
pd.dismiss();
}
}
enter code here
@EBean
public class BackgroundTask
{
@RootContext
Activity apda;
@Background
public void backGroundMethod()
{
try
{
TimeUnit.SECONDS.sleep(10);
update();
}
catch(Exception e)
{
Log.e("Error",""+e);
}
}
@UiThread
public void update()
{
//((AnnotationProgressDialogActivity)apda).updateUI();
((AnnotationProgressDialogActivity)apda).dismissDialog();
}
}
答案 0 :(得分:1)
出现此错误是因为您保留对ProgressDialog的引用,ProgressDialog本身保留对已泄露的DecorView引用的已销毁活动的引用。
这是你应该做的事情:
另请注意,@RootContext Activity apda
可以替换为@RootContext AnnotationProgressDialogActivity apda
。