Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11517] Android: On clicking the back button of device on third window, application closes instead of going to the previous window

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionDuplicate
Resolution Date2012-10-18T00:59:47.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 3.1.0, 2012 Sprint 21 API, 2012 Sprint 21
ComponentsAndroid
Labelsqe-and100112, qe-testadded, regression
ReporterNeha Chhabra
AssigneeHieu Pham
Created2012-10-17T07:40:00.000+0000
Updated2013-10-07T07:07:41.000+0000

Description

On clicking the back button of device on third window,application closes instead of going to the previous window. This is regression.This works fine on 2.1.3.GA. Steps to reproduce: 1. Install and Launch app 2. Press "open red win" (See result) 3. Press "open yellow win" (see result) 4. Press the Android back button (see result). Expected Result: After Step #2: A "red" (pinkish) window opens with a "open yellow win" button After Step #3: A "yellow" window opens with a "close red win" and a "go home" button After step #4 You should return to the red window Actual result: After Step #2: A "red" (pinkish) window opens with a "open yellow win" button After Step #3: A "yellow" window opens with a "close red win" and a "go home" button After step #4: Application closes and returns to the menu screen of the device app.js
Titanium.UI.setBackgroundColor('#000');

gt = { ui:{} };

gt.ui.createNavigationGroup = function(options) 
{
	var navGroup = 
	{
    	stack: [],
        window: options.window,
        to_root:options.to_root || false
    };

    navGroup.open = function(win, options) 
    {
        Ti.API.info('pre open stack length: ' + navGroup.stack.length);
        
        if (navGroup.stack.length == 0) 
        {
            navGroup.window.addEventListener('android:back', navGroup.go_back);
            Ti.API.info('addEventListener android:back');
        }

        navGroup.stack.push(win);
        win.open(options);
        Ti.API.info('after open stack length: ' + navGroup.stack.length);
    };

    navGroup.close = function(win, options) 
    {
        var idx = navGroup.stack.indexOf(win);
        Ti.API.info('idx: ' + idx);
        if (idx != -1) navGroup.stack.splice(idx, 1);
        win.close(options);
        win = null;
    };

    navGroup.go_back = function(options) 
    {
        var win = navGroup.stack.pop();
        if (win) 
        {
            win.close(options);
            win = null;
        }

        if (navGroup.stack.length == 0) 
        {
            Ti.API.info('removeEventListener android:back');
            navGroup.window.removeEventListener('android:back', navGroup.go_back);
            Ti.API.info('navGroup window close');   
        }

    };

    navGroup.go_home = function() 
    {
        while (navGroup.stack.length) 
        {
            navGroup.go_back();
        }
    };

    return navGroup;

}

var tabGroup = Titanium.UI.createTabGroup();

var navWindow = Ti.UI.createWindow(
{
    backgroundColor:'#ccc',
    navBarHidden:false
});


var tabWindow = Ti.UI.createWindow(
{
    backgroundColor:'#ccc'
});

tabWindow.addEventListener('click', function()
{
    navTab.open(navWindow);
});


var navBtn = Ti.UI.createButton(
{
    title:'open red win',
    color:'#f00',
    width:200,
    height:40
});

navWindow.add(navBtn);


var nav = gt.ui.createNavigationGroup(
{
    window:navWindow
});


navBtn.addEventListener('click', function()
{
    var win = Ti.UI.createWindow(
    {
        backgroundColor:'#fcc'
    });


    var navBtn2 = Ti.UI.createButton(
    {
        title:'open yellow win',
        color:'#ff0',
        width:200,
        height:40
    });


    win.add(navBtn2);

    navBtn2.addEventListener('click', function()
    {
        var win2 = Ti.UI.createWindow(
        {
            backgroundColor:'#ffc'
        });


        var navBtn3 = Ti.UI.createButton(
        {
            title:'close red win',
            color:'#000',
            width:200,
            height:40,
            top:50
        });


        navBtn3.addEventListener('click', function()
        {
            nav.close(win);
        });

        win2.add(navBtn3);


        var navBtn4 = Ti.UI.createButton(
        {
            title:'go home',
            color:'#0f0',
            width:200,
            height:40,
            top:150
        });


        navBtn4.addEventListener('click', function()
        {
            nav.go_home(win);
        });

        win2.add(navBtn4);

        nav.open(win2);
    })


    nav.open(win);
})


var navTab = Ti.UI.createTab(
{
  id: 'navTab',
  title:'navGroup',
  window:navWindow
});

tabGroup.addTab(navTab);

tabGroup.open();

Comments

  1. Hieu Pham 2012-10-17

    master PR: https://github.com/appcelerator/titanium_mobile/pull/3237
  2. Tamila Smolich 2012-10-18

    Closing as a duplicate of TIMOB-11264.

JSON Source