2015-11-30 38 views
0

我有一個活動在啓動時運行,它處理全局配置並根據當前應用程序狀態確定要啓動的正確活動。由於Activity不需要任何UI,因此我使用Theme.NoDisplay,在onStart中完成我的工作,開始下一個活動並調用finish()。沒有UI的活動必須在onResume()完成之前調用finish()

<activity android:name=".StartUpActivity" android:theme="@android:style/Theme.NoDisplay> 

protected void onStart() { 
    super.onStart(); 

    doConfiguration(); 
    startServices(); 
    startNextActivity(); 
    finish(); 
} 

這工作正常,直到我需要添加異步服務調用。由於服務調用的onResume後返回(),我開始收到此錯誤:

An activity without a UI must call finish() before onResume() completes 

回答

3

要修正這個錯誤,我需要活動的主題改爲Theme.Translucent.NoTitleBar

<activity android:name=".StartUpActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"> 
+0

如需更多信息,請參閱[此博客文章](https://commonsware.com/blog/2015/11/02/psa-android-6p0-theme.nodisplay-regression.html)。 – CommonsWare

相關問題