Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3244] Android: tabbed applications fail (crash) in honeycomb

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2011-05-04T16:28:46.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.7.0, Sprint 2011-12
ComponentsAndroid
Labelsandroid, defect, honeycomb, release-1.7.0, reported-1.6.0
ReporterBill Dawson
AssigneeBill Dawson
Created2011-04-15T03:40:17.000+0000
Updated2011-05-04T16:28:46.000+0000

Description

app.js fail case:

Titanium.UI.setBackgroundColor('#000');
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});
var tab1 = Titanium.UI.createTab({  
    title:'Tab 1',
    window:win1
});

tabGroup.addTab(tab1);  
tabGroup.open();

Fail trace:

E/AndroidRuntime(  420): FATAL EXCEPTION: main
E/AndroidRuntime(  420): android.content.res.Resources$NotFoundException: Resource ID #0x0
E/AndroidRuntime(  420):    at android.content.res.Resources.getValue(Resources.java:1014)
E/AndroidRuntime(  420):    at android.content.res.Resources.loadXmlResourceParser(Resources.java:2039)
E/AndroidRuntime(  420):    at android.content.res.Resources.getLayout(Resources.java:853)
E/AndroidRuntime(  420):    at android.view.LayoutInflater.inflate(LayoutInflater.java:389)
E/AndroidRuntime(  420):    at android.widget.TabHost$LabelIndicatorStrategy.createIndicatorView(TabHost.java:534)
E/AndroidRuntime(  420):    at android.widget.TabHost.addTab(TabHost.java:226)
E/AndroidRuntime(  420):    at ti.modules.titanium.ui.widget.TiUITabGroup.addTab(TiUITabGroup.java:91)
E/AndroidRuntime(  420):    at ti.modules.titanium.ui.TabGroupProxy.addTabToGroup(TabGroupProxy.java:183)

Comments

  1. Bill Dawson 2011-04-15

    Here's some native code you can play with that mimics how we create tabs:

    HelloTabWidget.java

       package com.billdawson.android.hellotabwidget;
       
       import android.app.ActivityGroup;
       import android.content.Intent;
       import android.os.Bundle;
       import android.widget.FrameLayout;
       import android.widget.TabHost;
       import android.widget.TabWidget;
       
       public class HelloTabWidget extends ActivityGroup {
           /** Called when the activity is first created. */
           @Override
           public void onCreate(Bundle savedInstanceState) {
               super.onCreate(savedInstanceState);
               TabHost tabHost = new TabHost(this);  // The activity TabHost
               tabHost.setId(android.R.id.tabhost);
               TabWidget tabWidget = new TabWidget(this);
               tabWidget.setId(android.R.id.tabs);
               FrameLayout tabContent = new FrameLayout(this);
               tabContent.setId(android.R.id.tabcontent);
               tabHost.addView(tabWidget);
               tabHost.addView(tabContent);
               tabHost.setup(getLocalActivityManager());
               TabHost.TabSpec spec;  // Resusable TabSpec for each tab
               Intent intent;  // Reusable Intent for each tab
       
               // Create an Intent to launch an Activity for the tab (to be reused)
               intent = new Intent().setClass(this, ArtistsActivity.class);
               // Initialize a TabSpec for each tab and add it to the TabHost
               spec = tabHost.newTabSpec("artists").setIndicator("Artists")
                             .setContent(intent);
               tabHost.addTab(spec);
               setContentView(tabHost);
           }
       }
       

    ArtistsActivity.java

       package com.billdawson.android.hellotabwidget;
       
       import android.app.Activity;
       import android.os.Bundle;
       import android.widget.TextView;
       
       public class ArtistsActivity extends Activity
       {
       
           @Override
           public void onCreate(Bundle savedInstanceState)
           {
               super.onCreate(savedInstanceState);
               TextView textview = new TextView(this);
               textview.setText("This be the Artists tab");
               setContentView(textview);
           }
           
       }
       

    This native example creates the TabHost using new TabHost(...) like we do in our TiUITabGroup.java. It works fine in api 10 and lower, but not in api 11 (Honeycomb). If you alter the native code above (HelloTabWidget.java) so that HelloTabWidget extends TabActivity instead of ActivityGroup, then replace TabHost tabHost = new TabHost(this); with TabHost tabHost = getTabHost();, it will work fine in Honeycomb.

    I don't think we'll be able to solve this until we can see Honeycomb source code and see how the updated TabActivity creates its TabHost so we can do something similar. Some resource is missing, apparently. Maybe we need to do a .setId(...) on something.

  2. Don Thorp 2011-04-15

    Adding release-1.7.0 tag. May need to port back to 1.6.1. If we do then we'll add that tag then.

  3. Bill Dawson 2011-04-15

    https://github.com/appcelerator/titanium_mobile/commit/19728696a23a8f9d45e044ead3b39162c68706fb"> https://github.com/appcelerator/titanium_mobile/commit/19728696a23a...

  4. Bill Dawson 2011-04-15

    (from [19728696a23a8f9d45e044ead3b39162c68706fb]) Change TiTabActivity to inherit from TabActivity so as to use TabHost in the manner expected by android (TabActivity.getTabHost() rather than new TabHost()). This enables our default apps (the two-tab app that gets created when you create a new titanium project) to run on Honeycomb. [#3244] https://github.com/appcelerator/titanium_mobile/commit/19728696a23a8f9d45e044ead3b39162c68706fb"> https://github.com/appcelerator/titanium_mobile/commit/19728696a23a...

  5. Don Thorp 2011-05-04

    Verified on Xoom.

JSON Source