I am having one java class in that class as soon some one purchases our application then it will start downloading and progress dialog has to appear instead it goes to some other page and when i come out of the application and when i restart then it starts downloading.
Please Help me out from this mess...
Thank you
Check the condition for dialog, before showing.
Like this
if(pDialog!=null)
{
if(!pDialog.isShowing())
{
pDialog.show();
}
}
and also while removing the dialog in onPostexecute() check for null.
if Still not works just remove the pDialog and try once with your code.
Two causes for your error happen:
The error will happen if you're trying to show a Dialog after you've exited an Activity.
Also, if an unhandled Exception was thrown in your AsyncTask, which would cause the Activity to shutdown, then an open progress dialog will cause the Exception.
According to the Log you've posted, the error happens after you call pDialog.show() which might be the 1st cause I've mentioned before.
Also you are calling finish() in many parts of your code, maybe one of these calls are making your Activity to stop and leaking your Dialog.
You must check which one of them is finishing your Activity before you show the Dialog. A good solution is to dismiss the Dialog (if it's showing) before calling finish().
Related
Some people are getting this even tho I check if the activity is finishing or not. This app has a few million users and only 10 or so people are crashing. I am confused as to why.
private fun someFun(headerTitle: String, message: String) {
if (isFinishing) return
ComponentPopup.Builder(this)
.setTitleText(headerTitle)
.setMessageText(message)
.setPositiveButtonText("Some text")
.setNegativeButtonText("Some text")
.createPopup()
.show()
}
ComponentPopup is just a custom component that extends Dialog.
Crashlytics says I get this exception at .show(). I don't call this function on a background thread either. Only on onBackPressed().
What gives? Why do I get this exception even though I check isFinishing?
Tried to finish the activity manually. Still wasn't able to produce the problem.
I was getting the same exception. In my case the issue was I was passing the application context to the Builder instead of the Activity context. Hopefully, you are not doing so.
Just for testing, you may pass the context of your current Activity as YOUR_ACTIVITY.this instead of this.
This Issue happens when the user leave the activity before the diloag shown. So the dilaog didn't get the window of the specified Actvity to be show on.
You can generate the crash by calling the show of dialog and then instantly leave the activity.
I have got this code in my Async task to go to a new activity when doInBackgound is completed, but no matter what I do, I always get the window leak error, I have also tried adding delay to the the progress bar, but with no success. Can anyone help me? Thanks
Problem is your Activity is finished and the ProgressDialog is theoretically still "displaying" which is not possible (since the Activity where it is displayed is gone), hence this error occurs. To prevent it remove the Handler around the dialog dismiss then it should work :)
I am using a dialog fragment to show loading message when app is launched for first time.
I am using public void show(FragmentManager manager, String tag) method to display the dialog.
This loading message will be dismissed after data loading is done by intent service.
I am using dismissAllowingStateLoss() to close the dialog.
I didnt use dismiss() method as the app was crashing sometimes. But with dismissAllowingStateLoss(), the dialog was not being dismissed sometimes ( very rarely once in 100 times).
I have searched many blogs about this issue, but couldnt get the root cause.
Does anyone face such issue or have any idea about this kind of issue. Please suggest
Have you tried something like this
getFragmentManager().beginTransaction().remove(yourFragment).commit();
If this doesnt solve the issue, please post some source-code so that we can try and assist you.
I need to show a yes/no dialog in AsyncTask.onPostExecute() but I keep getting
java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
when the screen is rotated just before the dialog is shown. I had a similar problem showing dialogs in the onActivityResult but have since moved the dialogs to the
onPostResume() as suggested by other posts but I am unable to solve this one.
Is it possible to show a yes/no dialog in the onpostexecute() without causing exception and without using "commitAllowingStateLoss"?
Your help is much appreciated.
I think you should maintain state of your activity in which you are calling the dialog, because every time when activities orientation changes onCreate() function calls and if you are initiating any AsyncTask in it, then it will execute it again. May be that's why you are facing the problem. Just maintain its state and then check it, hope it will help you.
Just add this code in your manifest file for that activity. Just type landscape or portrait according to your need.
android:screenOrientation="portrait/landscape"
Thank you.
While running monkey tool on my app, I am getting android.view.WindowLeaked exception, I referred some stackoverflow threads and found that we need avoid this while creating popups, instead we need to use getApplicationContext() but this is causing BadTokenException
E/AndroidRuntime(5597): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
Again after searching through I found this answer which says
One cause of this error may be trying to display an application
window/dialog through a Context that is not an Activity
So how to solve this?
Usually window leaks because You don't use showDialog method in Activity but only using Dialog.show() method.
When dialog is displayed and configuration of Your Activity changes (eg. orientation change) dialog has not window to attach, and this results in leak of window.
If You use Compatibility library You should use DialogFragment instead of pure dialog.
the reason behind WindowManager$BadTokenException is that you keep showing dialog or popupwindow on the window whose context is not alive now.
So should always dismiss popup or dialog whenever you switch between activities or dismiss any activity.
Therefore you should probably call dilog.dismiss() in onPause method.
onPause()
{
dilog.dismiss()
}