體驗活動生命週期遇到的錯誤
log:
2019-02-05 21:22:31.400 25240-25240/com.example.activitylifecycletest E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.activitylifecycletest, PID: 25240
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activitylifecycletest/com.example.activitylifecycletest.DialogActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
原因:
設置一個對話框式的活動,在AndroidMainfest.xml的<activity>標籤的配置如下:
<activity android:name=".DialogActivity"
android:theme="@android:style/Theme.Dialog"/>
從log中得知需要改爲Theme.AppCompat theme (或者 descendant)
究竟爲何能力不足,暫未分析。
修改如下:
<activity android:name=".DialogActivity"
android:theme="@style/Theme.AppCompat.Dialog" />
錯誤消失,出現對話框。
暫時告一段落,待後期解決。