Recommended approach for handling Android P dialogs

时间:2018-11-13 07:47:40

标签: android

It seems that Fragments are deprecated in Android P. I am reading a book where they are used (which is not really strange after all) and I am trying to decide which is the best approach to deal with Dialogs. In the relevant guide in the documentations the recommended approach suggest using the DialogFragment from the support library and not from the Android P library since it's deprecated. I did not expect all the relevant guides to be updated to point to the today recommended approach but to me it's a bit confusing.

As I see it I have 2 options:

  1. I can use support library and make my code work as it was meant to work before Android P. This of course comes with a cost of using a support library element (for example in my application size).
  2. Use the recommended approach for handling Android P Dialogs.

Well, my question is since I am in the step of learning (and I don't have an existing project to maintain for example) which is the recommended approach for Dialogs? The guide refers that:

Using DialogFragment to manage the dialog ensures that it correctly handles lifecycle events ...

and I know that using DialogFragment guaranteed that my application would work flawlessly in every lifecycle event (if for example smart phone was rotated etc). So I probably shouldn't rely on Dialog class itself either. So, which is the recommended approach?

0 个答案:

没有答案