PSA: Android 6.0 Theme.NoDisplay Regression



id="hist_frame" name="hist_frame2076234133" class="ss" tabindex="-1" style="height: 30px; left: -100px; position: absolute; top: -100px; width: 30px; font-family: Roboto, arial, sans-serif; font-size: 13px;">
与合适的人分享合适的内容。
首页
个人资料
人脉
收藏集
热门
社群
活动
环聊
信息页
设置
反馈
帮助  ·   地区
隐私权  ·   条款  ·   地图条款
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.
翻译
154
40
Ankur Nigam的个人资料照片 陈剑锋(chenupt)的个人资料照片 Jomar Tigcal的个人资料照片 Chris Boyle的个人资料照片
8 条评论
翻译
Chris P
2015年11月5日
+
5
6
5
 
Public Service Annoucement
翻译
翻译
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 used Theme.Translucent.NoTitleBar. 
翻译
翻译
翻译
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 ?
翻译
翻译
发表评论…

id="hist_frame" name="hist_frame2076234133" class="ss" tabindex="-1" style="height: 30px; left: -100px; position: absolute; top: -100px; width: 30px; font-family: Roboto, arial, sans-serif; font-size: 13px;">
与合适的人分享合适的内容。
首页
个人资料
人脉
收藏集
热门
社群
活动
环聊
信息页
设置
反馈
帮助  ·   地区
隐私权  ·   条款  ·   地图条款
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.
翻译
154
40
Ankur Nigam的个人资料照片 陈剑锋(chenupt)的个人资料照片 Jomar Tigcal的个人资料照片 Chris Boyle的个人资料照片
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 on b.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 used Theme.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
翻译
发表评论…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值