I am using Android annotation.There is a progress dialog but when i am rotating the screen (land to port) . The progress dialog dismiss and showing these error's in log cat.
Activity com.example.progressdialog.AnnotationProgressDialogActivity_ has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40661c20 that was originally added here
android.view.WindowLeaked: Activity com.example.progressdialog.AnnotationProgressDialogActivity_ has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40661c20 that was originally added here
and here is my code:-
@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();
}
}
This error appears because you are keeping a reference to the ProgressDialog that is itself keeping a reference to the destroyed activity that has a reference to the leaked DecorView.
Here is what you should do instead:
Also notice that @RootContext Activity apda
can be replaced with @RootContext AnnotationProgressDialogActivity apda
.