0

I have a tabhost widget which starts different activies by using Intents.

TabSpec tab = mTabHost.newTabSpec("profile");
tab.setIndicator("profile");
Intent i3 = new Intent(ctx, ProfileActivity.class);
tab.setContent(i3);
mTabHost.addTab(tab);

All childs are defined as embeded:

    <activity android:exported="false" android:name="com.example.app.ProfileActivity" android:label="ProfileActivity view">
       <intent-filter>
          <category android:name="android.intent.category.EMBED"></category>
          <action android:name="android.intent.action.MAIN"></action>
       </intent-filter>
    </activity>

Unfortunately I can see an occasional crash inside my ProfileActivity onResume function.

It crashes on this line, because getParent() returns null.

((MainActivity) getParent()).goToTab("splash")

It's not happening all the time - it's very occasional.

Anyone had this problem?

Charles
  • 50,943
  • 13
  • 104
  • 142

1 Answers1

0

As Documentation says: public final Activity getParent () Since: API Level 1

Returns the parent activity if this view is an embedded child.

Is your Activity an embedded child? If yes then it will return parent activity context otherwise null

Harish Godara
  • 2,388
  • 1
  • 14
  • 28