Search code examples
androidtitaniumappceleratortitanium-mobile

Titanium Android: View not attached to window manager chrash


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();
    }
}

Solution

  • 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();
    });