I have Two Activity Inside TabHost 1.PlayingActivity 2.AlbumActivity
By Clicking Button inside AlbumActivty will jump to LIstActivity ->By clicking Item in ListActivity, I want to jump back to one of the method inside-PlayingActivity w/o Losing Tab Layout.
I can accomplish task by calling Activity n specific Method using these
Class SongList extends ListActivty
{
public void onCreate(Bundle savedInstanceState)
{
//implemented list adapter-ls
listadapter. . . .
ls.setOnItemClickListener(New View.onItemClickListener)
{
public void onItemClick(AdapterView<?> parent, View view, int position,
long id)
{
int songIndex=position;
Intent i=new Intent(getApplicationContext(),AlbumActivity.class);
i.putExtra("methodName", "myMethod");
i.putExtra("index", songIndex);
startActivity(i);
}
}
}
}
public class MainActivity extends TabActivity {
private static final String NOW_PLAYING = "Playing";
private static final String ALBUM = "Album";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Playing Tab
TabSpec PlayingSpec = tabHost.newTabSpec(NOW_PLAYING);
// Tab Icon
PlayingSpec.setIndicator(NOW_PLAYING, getResources().getDrawable(R.drawable.icon_now_playing));
Intent PlayingIntent = new Intent(this, PlayingActivity.class);
// Tab Content
PlayingSpec.setContent(PlayingIntent);
// Album Tab
TabSpec AlbumSpec = tabHost.newTabSpec(ALBUM);
AlbumSpec.setIndicator(ALBUM, getResources().getDrawable(R.drawable.icon_music));
Intent AlbumIntent = new Intent(this, AlbumActivity.class);
AlbumSpec.setContent(AlbumIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(PlayingSpec); // Adding Playing tab
tabHost.addTab(AlbumSpec); // Adding Album tab
}
}
class PlayingActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
}
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
String index=intent.getStringExtra("index");
if(intent.getStringExtra("methodName").equals("myMethod")){
playSong(Integer.parseInt(index));
}
}
private void playSong(int i)
{
}
}
Just Found out that. Little bit of logic have saved my time.
Adding
finish();
inside the activity would done all my work.