Android: Changed dialog order after Activity

Two dialog boxes are open in my activity.

Dialog1, and then Dialog2 over Dialog1 (both can be seen, one overlays the other).

I open another action, and when I return to my original activity through the task manager, the order of the dialogs has changed. Now I see Dialog1 over Dialog2.

How can I maintain the order of the dialogs when I return my activity from the TaskManager ??

+4
source share
2 answers

I had a similar issue with ordering DialogFragments. In my case, I had a dialog to set a time period, and so he had to run another dialog to select dates. Therefore, after displaying the second dialog and changing the screen orientation, the order of the two dialogs is reversed, similar to your problem.

So my solution was to create a FragmentActivity that looks like a dialog. Then I replaced it with the first dialog. That way, I could better manage the state of the instance state, etc. With a life cycle of activity. This activity was then called, as usual, the second dialogue, without transferring anything else.

My other action, which was actually called the previous (first) dialogue, then simply caused a new action for the result, and it was!

Here's more details on how to make an activity look like a dialogue:

class MyDialogActivity extends FragmentActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_dialog_layout); LayoutParams params = getWindow().getAttributes(); params.height = LayoutParams.WRAP_CONTENT; params.width = LayoutParams.WRAP_CONTENT; getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); setTitle("my dialogs title"); setTheme(DialogFragment.STYLE_NORMAL); // ... } 

Hope this helps you, or at least gives you an idea of ​​a workaround for this ugly Android bug! Best wishes.

+1
source

I had a similar problem. I created the first DialogFragment object. Then I created the second by first. The problem arose when I turned my phone. In this case, the first DialogFragment has moved to the second.

The problem seems to be that I created the first DialogFragment in the same place (method) where I fire another DialogFragment.

I did something like:

 FirstDialogFragment a=FirstDialogFragment.newInstance(...); a.show(getSupportFragmentManager(),""); anotherDialogFragment.dismiss(); ..... // then somewhere in another method SecondDialogFragment b=SecondDialogFragment.newInstance(...); b.show(getSupportFragmentManager(),""); 

The problem was resolved when I put "anotherDialogFragment.dismiss ()" before "FirstDialogFragment.newInstance ()".

0
source

All Articles