0

I was going through code of one rather skilled developer and saw this:

new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.Theme_DeviceDefault));

And since this is the only reason to build application against API 14 it makes me wandering about benefits of this approach. I can't see any. I don't think it'll help against Exceptions when you call .show() or .dismiss() on Dialog with dead activity, and I can't think of anything else.

Thanks in advance.

romkansk
  • 63
  • 7

1 Answers1

1

This is the way to set dialog theme for builder before API 11. Constructor with second parameter was added only from API 11. There was no other was to set theme for builder before. Here is explanation with example.

Community
  • 1
  • 1
Leonidos
  • 10,482
  • 2
  • 28
  • 37
  • This would make sense if theme was custom, but since he used R.style.Theme_DeviceDefault it seems useless. – romkansk Jan 22 '13 at 16:49
  • Not really. He wanted default dialogs. But his application or some activities could have custom themes. So hi tells: "do not use current activity theme (returned by getActivity()), use default theme". – Leonidos Jan 22 '13 at 16:53
  • I think I know what you mean, but it still seems unreasonable. Theme_DeviceDefault was only added in API 14, will it still lead to default theme on devices with earlier API? And if not, he could've used new constructor. – romkansk Jan 22 '13 at 18:07
  • Yeah, you are right. I should be more attentive, I didnt noticed some details. R is android's R or project's R? – Leonidos Jan 22 '13 at 19:49
  • R is android R in this case. But I think you were right from the start. My gues is that he just copy-pasted this code from another class in this project and changed theme from custom to DeviceDefault. Thank you for your reply. – romkansk Jan 22 '13 at 22:45