今天程序在樂phone上測出來一個bug:
從頁面內(nèi)退出程序時候第一次退不出去,需要第二次推出才可以。
在DDMS上跟蹤發(fā)現(xiàn)報兩個錯誤:
08-19 13:51:18.286:
ERROR/AndroidRuntime(5765): java.lang.SecurityException: Permission
Denial: starting Intent {
act=android.intent.action.MAIN cat=[android.intent.category.HOME]
flg=0x10000000 cmp=com.android.launcher/.Launcher}
from ProcessRecord{302a32c0 5765:com.up591.android/10087}
(pid=5765, uid=10087) requires android.permission.REORDER_TASKS
08-19 14:16:04.576: ERROR/AndroidRuntime(6302): java.lang.SecurityException:
Permission Denial: starting Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME]
flg=0x10000000 cmp=com.android.launcher/.Launcher } from ProcessRecord{2ffee120 6302:com.up591.android/10087}
(pid=6302, uid=10087) requires android.permission.REORDER_TASKS
以及
08-19 14:17:13.446: ERROR/WindowManager(6428): Activity com.up591.android.view.MainActivity has leaked
window com.android.internal.policy.impl.PhoneWindow$DecorView@2fd590c8 that was originally added here
08-19 14:17:13.446: ERROR/WindowManager(6428): android.view.WindowLeaked: Activity com.up591.android.view.
MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@2fd590c8 that
was originally added here
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.view.ViewRoot.<init>(ViewRoot.java:247)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.view.Window$LocalWindowManager.addView(Window.java:444)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.app.Dialog.show(Dialog.java:248)
08-19 14:17:13.446: ERROR/WindowManager(6428): at com.up591.android.asyncTasks.NetworkTask.onPreExecute(NetworkTask.java:51)
08-19 14:17:13.446: ERROR/WindowManager(6428): at
com.up591.android.asyncTasks.GetRootCatalogTask.onPreExecute(GetRootCatalogTask.java:38)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.os.AsyncTask.execute(AsyncTask.java:391)
08-19 14:17:13.446: ERROR/WindowManager(6428): at com.up591.android.view.PractiseActivity.getList(PractiseActivity.java:221)
08-19 14:17:13.446: ERROR/WindowManager(6428): at
com.up591.android.view.PractiseActivity.onAfterCreate(PractiseActivity.java:79)
08-19 14:17:13.446: ERROR/WindowManager(6428): at com.up591.android.common.BaseActivity.onCreate(BaseActivity.java:122)
08-19 14:17:13.446: ERROR/WindowManager(6428): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2534)
08-19 14:17:13.446: ERROR/WindowManager(6428): at
android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
08-19 14:17:13.446: ERROR/WindowManager(6428): at
android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
08-19 14:17:13.446: ERROR/WindowManager(6428): at
android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:692)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.widget.TabHost.setCurrentTab(TabHost.java:354)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.widget.TabHost.addTab(TabHost.java:230)
08-19 14:17:13.446: ERROR/WindowManager(6428): at com.up591.android.view.MainActivity.onCreate(MainActivity.java:51)
08-19 14:17:13.446: ERROR/WindowManager(6428): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2710)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.app.ActivityThread.access$2300(ActivityThread.java:131)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2049)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.os.Looper.loop(Looper.java:123)
08-19 14:17:13.446: ERROR/WindowManager(6428): at android.app.ActivityThread.main(ActivityThread.java:4737)
08-19 14:17:13.446: ERROR/WindowManager(6428): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 14:17:13.446: ERROR/WindowManager(6428): at java.lang.reflect.Method.invoke(Method.java:521)
08-19 14:17:13.446: ERROR/WindowManager(6428): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876)
08-19 14:17:13.446: ERROR/WindowManager(6428): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634)
08-19 14:17:13.446: ERROR/WindowManager(6428): at dalvik.system.NativeStart.main(Native Method)
大概的意思是:第一個是說系統(tǒng)沒有改變Z軸排列任務(wù)的權(quán)限
第二個是說 窗體泄露錯誤
在谷歌后發(fā)現(xiàn)。窗體泄露的原因是有些dialog或則processDialog等引起的。這些空間依附的Activity已經(jīng)關(guān)閉而這些控件還在運行中。所以導(dǎo)致bug
典型的場合是activity 和dialog同時顯示 要先dialog.dismiss() 后activity.finish() 如果直接finish() 會出錯 但不影響功能。
解決的辦法是通過加入android.permission.REORDER_TASKS 權(quán)限解決
目前還不知道是不是因為沒有權(quán)限所以導(dǎo)致樂phone不能夠很好的釋放頁面資源。有待進一步研討