Dialog fragment dialog not dismissing sometimes - android

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.

Related

android.view.WindowLeaked(Progress dialog is leaking to new 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 :)

Activity has leaked window?

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().

How to show a yes/no dialog in AsyncTask onPostExecute()

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.

Croutons not showing properly - CroutonQueue somehow stuck?

I'm facing a serious problem with the Croutons Notification Library,
When i quickly switch my activites, sometimes (very often indeed) croutons for updates, like missing credentials, or "insert date first" are not shown anymore,
and so the users stay without any info, what's the problem.
For instance also the simple usecase:
Login To Application,
Logout,
try to re-login but with false credentials,
doesnt show a crouton anymore.
I tried:
Courton.clearAllNotifcations() in inPause(),
and additionally,
Crouton.clearCroutonsForActivity(this) too in onPause(),
to maybe solve the Problem, but it didn't.
I also debugged in the CroutonLibrary and the problem seems to be,
a Crouton gets added to queue, the the activity gets finished, the something finishes (like aSyncTask showing a crouton in onPostExecute(), this one gets added to the queue again, and then the queue is stuck.
Also.clearAllNotifications (which actually clears the queue) doesn't work, because the courton (asynctask finishes after acitvity.finish()) gets added afterwards, and the problem persists.
also tried:
#Override
protected void onDestroy() {
Crouton.clearCroutonsForActivity(this);
Crouton.cancelAllCroutons();
super.onDestroy();
}
knwon issue: https://github.com/keyboardsurfer/Crouton/issues/24
but didn't work too...
Thankful for any advice!
:)
You have found the correct issue on Crouton and the part of the code that is responsible for producing the issue.
In your case it correlates with the AsyncTask which is still running when your Activity actually should have been destroyed already. It's generally a good thing to move long running behavior out of user facing components, i.e. using a service layer.
Until then canceling the AsyncTask should do the trick.
thx #keyboardsurfer for the explanation...
adding...
and extracting the AsyncTask to a member variable...
#Override
protected void onPause() {
Crouton.clearCroutonsForActivity(this);
if (loadTasksTask != null) {
loadTasksTask.cancel(true);
}
super.onPause();
}
fixed the issue! :)
thx a lot :)

How can I guarantee a Dialog will be re-formed after canceled?

I have a dialog that pops up some information on a list, when a long click is performed. The information depends on which list entry the click is performed on. However, I'm noticing that when I view the information, and close it (Via calling it with a dialog.cancel() command), that the next time I open the dialog, it doesn't bother to get the information again, it just pops up the same dialog that I saw before. Any tips for overcoming this problem? Thanks!
Some further information. The dialog is generated using a showDialog(int) command. From there, it is called through an onCreateDialog(int) command in a master activity.
EDIT: I managed to get this to work by using the removeDialog(int) command in the onClickListener of the Dialog (It just removes itself when it dies). I can't for the life of me find a more elegant solution, but I'd much prefer one. Thanks guys!
Edit: NM, realized the answer was already posted here... Thanks again!
We could use more info, but are you using onPrepareDialog(int id, Dialog dialog) or onPrepareDialog(int id, Dialog dialog, Bundle args)?
You should let the activity handle the creation and showing of Dialogs. onPrepareDialog will ensure the dialog has the correct info before it is displayed to the user.
You need to rerun the routine that populated the dialog in the first place.

Categories

Resources