Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-24940] Android: Problem with setTimeout and Toolbar on API 16/17

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2017-08-25T22:34:53.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.2.0
Componentsn/a
Labelsmerge-6.2.0
ReporterYordan Banev
AssigneeYordan Banev
Created2017-07-06T12:02:48.000+0000
Updated2017-08-28T17:51:36.000+0000

Description

Happens on x86 emulators with Android API 16 or 17. When calling a timed out methods of Toolbar the application restarts after a native 'corrupted stack' error is logged. Application's theme must be set to Theme.Titanium for this example to work. Add the following in the tag in tiapp.xml:
  <android 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <manifest>
      <application android:theme="@style/Theme.Titanium"/>
    </manifest>
  </android>
*Steps to reproduce:* 1. Run the application. 2. Click on the "Button" button once. 3. Wait 3-4 seconds after the overflow menu is shown.

Test case:

var window = Ti.UI.createWindow();

var toolbar = Ti.UI.createToolbar({
    extendBackground: false,
    barColor: 'blue',
    width: Ti.UI.FILL,
    top: 0,
    logo: 'logo.png',
    overflowIcon: 'git.png',
    navigationIcon: 'logo2.jpg'
});

var button = Ti.UI.createButton({
    title: 'Button',
    right: 10,
    top: 0
});

button.addEventListener('click', function(e) {
    Ti.API.info('BackgroundColor is ' + toolbar.getBackgroundColor());
    Ti.API.info('Title is ' + toolbar.getTitle());
    Ti.API.info('Subtitle is ' + toolbar.getSubtitle());
    Ti.API.info('Logo is ' + JSON.stringify(toolbar.getLogo()));
    Ti.API.info('Overflow icon is ' + JSON.stringify(toolbar.getOverflowIcon()));
    Ti.API.info('Navigation icon is ' + JSON.stringify(toolbar.getNavigationIcon()));
  
    toolbar.showOverflowMenu();
  
    setTimeout(function() {
        Ti.API.info('Is overflow menu showed? - ' + toolbar.isOverflowMenuShowing());
      
        toolbar.hideOverflowMenu();
        toolbar.setLogo('logo2.jpg');
        toolbar.setNavigationIcon('git.png');
        toolbar.setOverflowIcon('logo.png');
        toolbar.collapseActionView();
        toolbar.dismissPopupMenus();
        toolbar.setBarColor('red');
        toolbar.setTitle('New Title');
        toolbar.setTitleTextColor('orange');
        toolbar.setSubtitle('New Subtitle');
        toolbar.setSubtitleTextColor('blue');
      
        Ti.API.info('Content inset end is ' + toolbar.getContentInsetEnd());
        Ti.API.info('Content inset end with actions is ' + toolbar.getContentInsetEndWithActions());
        Ti.API.info('Content inset left is ' + toolbar.getContentInsetLeft());
        Ti.API.info('Content inset right is ' + toolbar.getContentInsetRight());
        Ti.API.info('Content inset start is ' + toolbar.getContentInsetStart());
        Ti.API.info('Content inset start with navigation is ' + toolbar.getContentInsetStartWithNavigation());
    }, 3000);
});

window.add(toolbar);

window.activity.onCreateOptionsMenu = function(e) {
    var menu = e.menu;
    
    var menuItem = menu.add({
        title: 'Item 1',
        showAsAction: Ti.Android.SHOW_AS_ACTION_NEVER
    });
    
    menuItem.addEventListener('click', function(e) {
        Ti.API.debug('Item 1 was clicked');
    });
    
    var menuItem2 = menu.add({
        title: 'Item 2',
        showAsAction: Ti.Android.SHOW_AS_ACTION_NEVER
    });
    
    var menuItem3 = menu.add({
        title: 'Item 3',
        showAsAction: Ti.Android.SHOW_AS_ACTION_NEVER
    });
    
    var menuItem4 = menu.add({
        title: 'Item 4',
        showAsAction: Ti.Android.SHOW_AS_ACTION_NEVER
    });
};

window.activity.supportToolbar = toolbar;

var picker = Ti.UI.createPicker();

var data = [];
data[0]=Ti.UI.createPickerRow({title:'Bananas'});
data[1]=Ti.UI.createPickerRow({title:'Strawberries'});
data[2]=Ti.UI.createPickerRow({title:'Mangos'});
data[3]=Ti.UI.createPickerRow({title:'Grapes'});

picker.add(data);
toolbar.setItems([picker,button]);
window.addEventListener('open', function() {
    window.activity.setSupportActionBar(toolbar);
    toolbar.setBarColor('blue');
    toolbar.setTitle('Title');
    toolbar.setTitleTextColor('red');
    toolbar.setSubtitle('Subtitle');
    toolbar.setSubtitleTextColor('green');    
    toolbar.setContentInsetEndWithActions(10);
    toolbar.setContentInsetStartWithNavigation(11);
    toolbar.setContentInsetsAbsolute(12,12);
    toolbar.setContentInsetsRelative(13, 13);
});

window.open();

Comments

  1. Yordan Banev 2017-07-06

    PR: https://github.com/appcelerator/titanium_mobile/pull/9196
  2. Abir Mukherjee 2017-08-24

    [~ybanev] Can you please provide backport to 6.2.0 for this ticket?
  3. Yordan Banev 2017-08-25

    6_2_X: https://github.com/appcelerator/titanium_mobile/pull/9358
  4. Abir Mukherjee 2017-08-25

    FR passed. PR merged. Changes are seen in SDK's: 6.2.0.v20170827172423 7.0.0.v20170828071347

JSON Source