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 條評論
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
翻譯
發表評論…

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 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
翻譯
發表評論…

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章