Java – Bug Run Android tutorial HelloTabWidget under SDK 1.5: “setCurrentTag(getIntent())”

Bug Run Android tutorial HelloTabWidget under SDK 1.5: “setCurrentTag(getIntent())”… here is a solution to the problem.

Bug Run Android tutorial HelloTabWidget under SDK 1.5: “setCurrentTag(getIntent())”

Do not compile. In fact: even in 1.5, this api getIntent() has been listed as deprecated.

The error message I get says getIntent() doesn’t return a string, but setCurrentTab() requires one.

If I guess and change the line to:

“tabHost.setCurrentTab(1);//is setCurrentTab(getIntent()”,

Then it compiles, builds, but doesn’t run. I get an “unexpected stop” error message from the emulator. I can’t even get Log.d to output, so it seems to have stopped “unexpectedly” quite early.

So the first and main problem is: What is the correct fix for “tabHost.setCurrentTab(getIntent()” in the last line of OnCreate() in http://developer.android.com/resources/tutorials/views/hello-tabwidget.html? ?

The second and simpler question is: replace “mTabHost” with tabHost where this happens, am I guessing right?

Solution

Here are the issues and fixes for that particular tutorial:

Step 2: When creating activities, you need to manually add them to the list if you didn’t create them from list.

Add these lines to the AndroidManifest.xml:

  <activity android:name=". AlbumsActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
        </activity>
  <activity android:name=". ArtistsActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
        </activity>
          <activity android:name=". SongsActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
        </activity>

Step 3: You are only instructed to create ic_tab_artists.xml files. You also need to create one for ic_tab_songs.xml and ic_tab_albums.xml. You can copy just the ic_tab_artists.xml (or change the HelloTabView.java tab specification to use the artists.xml file for each tab).

Step 4: The penultimate line under /res/layout/main has a typo (a; Instead of 🙂

      android:padding="5dp" />
    </LinearLayout>
</TabHost>

Step 6: There is a typo using the call mTabHost instead of tabHost. Change it.

As mentioned earlier, the getIntent() function on the last line is inappropriate. I just call the tab based on its ID. For example:

 tabHost.setCurrentTabByTag("albums");

Related Problems and Solutions