'Hidden DialogFragment gets shown again when activity is resumed

I have a DialogFragment I manually hide it via this.dialog.hide(), if I put the app to the background, such as pressing the home button, and click the app again, it brings up the activity, but also shows the hidden DialogFrament. This is not the behavor I expect. I would like to still keep the DialogFragment hidden, and only show it whenever I need to by calling this.dialog.show(). The reason why not remove it is beause I want to keep its state and it is re-used for many times, the initilization is expensive.

Is there a way not showing the DialogFragment when the activity is resumed?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source