您的位置:首页 > 移动开发 > Android开发

PSA: Android 6.0 Theme.NoDisplay Regression

2015-11-16 11:25 806 查看
登录

加入 Google+与合适的人分享合适的内容。首页个人资料人脉收藏集热门社群活动环聊信息页设置反馈帮助 · 地区隐私权 · 条款 · 地图条款

Dianne Hackborn添加到圈子29,255 位关注者|3,284,128 次查看

Dianne Hackborn

公开分享 - 2015年11月5日 PSA: The new requirement to immediately finish an activity if using Theme.NoDisplay is not a regression, this has always been a requirement of it (see https://developer.android.com/reference/android/R.style.html#Theme_NoDisplay for example).

The reason the platform in M is now crashing the app if it doesn't use this is because not using it would previously break in very subtle and mysterious ways. For example, you would sometimes end up with your app ANRing for no reason.

Why is this? Because what Theme.NoDisplay actually does is completely prevent the window for the activity from being shown. That is, the activity gets launched, but a window for it is never displayed.

If you don't immediately finish the activity in this situation, the app is in a bad state: it has an activity being launched that the system is waiting for a window to be displayed for, but no window will ever appear. So depending on how the timing goes, you can end up with the system sitting there waiting to see the window appear, which it never does, and bam you have ANRed.

We realized we were repeatedly debugging reports from developers of their apps ANRing when they shouldn't be, tracking those problems down to misuse of Theme.NoDisplay causing their random ANRs. It is better for all of us if the platform catches this consistently, early, with a clear message about what the app did wrong.

If you really need to have a transparent activity that doesn't immediately finish, you can use Theme.Translucent.NoTitleBar to have a window that is completely transparent.翻译The CommonsBlog — PSA: Android 6.0 Theme.NoDisplay Regressioncommonsware.comMark Murphy's CommonsBlog15440







8 条评论

Shuhrat Dehkanov2015年11月5日

Sorry, but what does PSA stand for? 翻译

Chris P2015年11月5日+5
6
5
Public Service Annoucement翻译

David Gerber2015年11月5日

The real problems: 1) lack of documentation 2) no useful response onb.android.com翻译

Said Tahsin Dane2015年11月5日+1
2
1
I just created a library today which creates an Activity with no UI just to request a permission. I first wondered that why my sample application does not crash. Then, I realized that I actually usedTheme.Translucent.NoTitleBar. 翻译

Marius Gedminas2015年11月7日

And what does ANR stand for?翻译

Dianne Hackborn2015年11月8日+1
2
1
+Marius Gedminas Application Not Responding翻译

Liran Barsisa2015年11月9日

I've never used this theme. What can be its purpose? Can you give an example?
Would this be a good example: opening an activity just to show a dialog ?翻译

meng wang2015年11月11日

top翻译发表评论…



登录





加入 Google+
与合适的人分享合适的内容。





首页



个人资料



人脉



收藏集



热门



社群



活动



环聊



信息页



设置

反馈

帮助 · 地区

隐私权 · 条款 · 地图条款





Dianne Hackborn

添加到圈子

29,255 位关注者|3,284,128 次查看






Dianne Hackborn

公开分享 - 2015年11月5日

PSA: The new requirement to immediately finish an activity if using Theme.NoDisplay is not a regression, this has always been a requirement of it (see https://developer.android.com/reference/android/R.style.html#Theme_NoDisplay for
example).

The reason the platform in M is now crashing the app if it doesn't use this is because not using it would previously break in very subtle and mysterious ways. For example, you would sometimes end up with your app ANRing for no reason.

Why is this? Because what Theme.NoDisplay actually does is completely prevent the window for the activity from being shown. That is, the activity gets launched, but a window for it is never displayed.

If you don't immediately finish the activity in this situation, the app is in a bad state: it has an activity being launched that the system is waiting for a window to be displayed for, but no window will ever appear. So depending on how the timing goes, you
can end up with the system sitting there waiting to see the window appear, which it never does, and bam you have ANRed.

We realized we were repeatedly debugging reports from developers of their apps ANRing when they shouldn't be, tracking those problems down to misuse of Theme.NoDisplay causing their random ANRs. It is better for all of us if the platform catches this consistently,
early, with a clear message about what the app did wrong.

If you really need to have a transparent activity that doesn't immediately finish, you can use Theme.Translucent.NoTitleBar to have a window that is completely transparent.

翻译

The
CommonsBlog — PSA: Android 6.0 Theme.NoDisplay Regression

commonsware.com

Mark Murphy's CommonsBlog

154
40









8 条评论





Shuhrat Dehkanov

2015年11月5日

Sorry, but what does PSA stand for? 

翻译





Chris P

2015年11月5日

+

5

6

5

Public Service Annoucement

翻译





David Gerber

2015年11月5日

The real problems: 1) lack of documentation 2) no useful response onb.android.com

翻译





Said Tahsin Dane

2015年11月5日

+

1

2

1

I just created a library today which creates an Activity with no UI just to request a permission. I first wondered that why my sample application does not crash. Then, I realized that I actually usedTheme.Translucent.NoTitleBar. 

翻译





Marius Gedminas

2015年11月7日

And what does ANR stand for?

翻译





Dianne Hackborn

2015年11月8日

+

1

2

1

+Marius
Gedminas Application Not Responding

翻译





Liran Barsisa

2015年11月9日

I've never used this theme. What can be its purpose? Can you give an example?

Would this be a good example: opening an activity just to show a dialog ?

翻译





meng wang

2015年11月11日

top

翻译

发表评论…
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: