Titanium Android: View not attached to window manager chrash

烈酒焚心 提交于 2019-12-11 11:55:07

问题


I have two views.In first view, I have a table view and I am displaying remote data in its cells. I am showing activity indicator while data downloading.

Second view gets open when any of row is selected.

When I come back to the first view, I am refreshing the table view by downloading remote data.

But in Android, when I come back to first view and start downloading data, application gets crash due to activity indicator !!! Application crashes only in Android, its working fine in iPhone !!

I am refreshing the table's data in focus event of current window.

the error : -

Activity org.appcelerator.titanium.TiActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@450c4488 that was originally added here E/WindowManager( 324): android.view.WindowLeaked: Activity org.appcelerator.titanium.TiActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@450c4488 that was originally added here

and

(main) [2225,140482] Sending event: exception on thread: main msg:java.lang.IllegalArgumentException: View not attached to window manager; Titanium 1.8.1,2012/01/27 17:31,a24502a E/TiApplication( 324): java.lang.IllegalArgumentException: View not attached to window manager

EDITED

my code : -

var currentWindow = Titanium.UI.currentWindow;

var placeTableData = [] ;
var placeTableView = Titanium.UI.createTableView
({
    data:placeTableData,
    top:'0dp',
    height:'365dp'
});

currentWindow.addEventListener('focus',winopened);
function winopened(e)
{
    placeTableData = createRow();
}

function createRow() 
{   
    currentWindow.add(activity);
    activity.show();    
    currentWindow.touchEnabled = false;

    // downloading data 

    if(loader1.DONE)
    {
        currentWindow.touchEnabled = true ;
        activity.hide();
    }
}

回答1:


Solved !!! I found that, in Android, when you press back button, it doesn't handle proper navigation to the previous view. It simply displays previous view without take care of current view.

So it necessary to close current view properly before displaying another view. So I closed current view before displaying the previous view.

When we press back button on Android, android:back event of Window get call. So I closed current window in this method , like :

Titanium.UI.currentWindow.addEventListener('android:back',function(e)
{
    Ti.API.info('back button pressed');
    currentWindow.close();
});


来源:https://stackoverflow.com/questions/9802302/titanium-android-view-not-attached-to-window-manager-chrash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!