Titanium Mobile
  1. Titanium Mobile
  2. TIMOB-3244

Android: tabbed applications fail (crash) in honeycomb

    Details

      Description

      {html}<div><p><strong>app.js fail case</strong>:</p>
      <pre>
      <code class="javascript">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();</code>
      </pre>
      <p>Fail trace:</p>
      <pre>
      <code>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)</code>
      </pre></div>{html}

        Issue Links

          Activity

          Hide
          Bill Dawson added a comment -
          {html}<div><p>Here's some native code you can play with that mimics how we
          create tabs:</p>
          <p><strong>HelloTabWidget.java</strong></p>
          <pre>
          <code class=
          "javascript">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); }
          }</code>
          </pre>
          <p><strong>ArtistsActivity.java</strong></p>
          <pre>
          <code class=
          "javascript">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); }

          }</code>
          </pre>
          <p>This native example creates the <code>TabHost</code> using
          <code>new TabHost(...)</code> 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
          <code>HelloTabWidget</code> extends <code>TabActivity</code>
          instead of <code>ActivityGroup</code>, then replace <code>TabHost
          tabHost = new TabHost(this);</code> with <code>TabHost tabHost =
          getTabHost();</code>, it will work fine in Honeycomb.</p>
          <p>I don't think we'll be able to solve this until we can see
          Honeycomb source code and see how the updated
          <code>TabActivity</code> creates its <code>TabHost</code> so we can
          do something similar. Some resource is missing, apparently. Maybe
          we need to do a <code>.setId(...)</code> on something.</p></div>{html}
          Show
          Bill Dawson added a comment - {html}<div><p>Here's some native code you can play with that mimics how we create tabs:</p> <p><strong>HelloTabWidget.java</strong></p> <pre> <code class= "javascript">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); } }</code> </pre> <p><strong>ArtistsActivity.java</strong></p> <pre> <code class= "javascript">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); } }</code> </pre> <p>This native example creates the <code>TabHost</code> using <code>new TabHost(...)</code> 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 <code>HelloTabWidget</code> extends <code>TabActivity</code> instead of <code>ActivityGroup</code>, then replace <code>TabHost tabHost = new TabHost(this);</code> with <code>TabHost tabHost = getTabHost();</code>, it will work fine in Honeycomb.</p> <p>I don't think we'll be able to solve this until we can see Honeycomb source code and see how the updated <code>TabActivity</code> creates its <code>TabHost</code> so we can do something similar. Some resource is missing, apparently. Maybe we need to do a <code>.setId(...)</code> on something.</p></div>{html}
          Hide
          Don Thorp added a comment -
          {html}<div><p>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.</p></div>{html}
          Show
          Don Thorp added a comment - {html}<div><p>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.</p></div>{html}
          Hide
          Bill Dawson added a comment -
          {html}<div><p><a href=
          "https://github.com/appcelerator/titanium_mobile/commit/19728696a23a8f9d45e044ead3b39162c68706fb">
          https://github.com/appcelerator/titanium_mobile/commit/19728696a23a...</a></p></div>{html}
          Show
          Bill Dawson added a comment - {html}<div><p><a href= "https://github.com/appcelerator/titanium_mobile/commit/19728696a23a8f9d45e044ead3b39162c68706fb"> https://github.com/appcelerator/titanium_mobile/commit/19728696a23a ...</a></p></div>{html}
          Hide
          Bill Dawson added a comment -
          {html}<div><p>(from <a href=
          "/projects/32238/changesets/19728696a23a8f9d45e044ead3b39162c68706fb"
          title=
          "Changeset [19728696a23a8f9d45e044ead3b39162c68706fb]">[19728696a23a8f9d45e044ead3b39162c68706fb]</a>)
          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. [<a href=
          "/projects/32238/tickets/3244" title="Ticket #3244">#3244</a>]
          <a href=
          "https://github.com/appcelerator/titanium_mobile/commit/19728696a23a8f9d45e044ead3b39162c68706fb">
          https://github.com/appcelerator/titanium_mobile/commit/19728696a23a...</a></p></div>{html}
          Show
          Bill Dawson added a comment - {html}<div><p>(from <a href= "/projects/32238/changesets/19728696a23a8f9d45e044ead3b39162c68706fb" title= "Changeset [19728696a23a8f9d45e044ead3b39162c68706fb] "> [19728696a23a8f9d45e044ead3b39162c68706fb] </a>) 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. [<a href= "/projects/32238/tickets/3244" title="Ticket #3244">#3244</a>] <a href= "https://github.com/appcelerator/titanium_mobile/commit/19728696a23a8f9d45e044ead3b39162c68706fb"> https://github.com/appcelerator/titanium_mobile/commit/19728696a23a ...</a></p></div>{html}
          Hide
          Don Thorp added a comment -

          Verified on Xoom.

          Show
          Don Thorp added a comment - Verified on Xoom.

            People

            • Assignee:
              Bill Dawson
              Reporter:
              Bill Dawson
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development