Note that there are some explanatory texts on larger screens.

plurals
  1. POonActivityResult() not called inside a TabHost
    text
    copied!<p>I have two Activities, one is a picker activity and the other is a list of choices. Once a choice is clicked, data is returned to the picker activity. </p> <p>These two activities are part of an activity group and the activity group is a TabSpec inside a TabHost.</p> <p>Everything works fine when the picker Activity is the launch activity. It also works fine when the ActivityGroup is the launch activity. It does not work (but no error) when the TabHost is the launch activity. Is there some Intent flag or getParent() I need to be doing to get this to work?</p> <pre><code>public class MyActivity extends Activity { static final int MY_REQUEST = 0; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_picker); Button button = (Button) findViewById(R.id.my_button); button.setOnClickListener(buttonOnClickListener); } private OnClickListener buttonOnClickListener = new OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MyActivity.this, SubActivity.class); startActivityForResult(inent, MY_REQUEST); } }; protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MY_REQUEST) { if (resultCode == RESULT_OK) { String item = data.getStringExtra("item"); //do something } } if (resultCode == RESULT_CANCELED) { } } } public class SubActivity extends Activity { private ArrayAdapter&lt;String&gt; adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_sublayout); ListView listView = (ListView) findViewById(R.id.list); String[] items = {"red", "blue", "black", "green"}; adapter = new ArrayAdapter&lt;String&gt;(this, android.R.layout.simple_expandable_list_item_1, items); listView.setAdapter(adapter); listView.setOnItemClickListener(listOnItemClickListener); } private OnItemClickListener listOnItemClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { Intent intent = new Intent(); String item = adapter.getItem(position); intent.putExtra("item", item); setResult(RESULT_OK, intent); finish(); } }; } </code></pre> <p>The code for launching the activity inside a tab is fairly standard but here it is:</p> <pre><code>public class TabsActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tabs); TabHost tabHost = getTabHost(); Intent intent= new Intent().setClass(this, MyActivityGroup.class); TabSpec tabSpecMyActivity = tabHost .newTabSpec(getString(R.string.my_title)) .setIndicator(getString(R.string.my_title)) .setContent(intent); tabHost.addTab(tabSpecMyActivity ); tabHost.setCurrentTab(0); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload