Question

Calling Specific Method from ListActivity which invokes method in one of the Parent(TabActivity) w/o Losing TabHost Layout

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

ListActivity clicking on Item invokes specific Method in PlayingActivity

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);
              }
        }
    }

}

MainActivity which host PlayingActivity & AblumActivity Under TabHost

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
}

}

In PlayingActivity called specific method(playSong())

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)
   { 
   }
} 

Now the Catch iz I can somehow invokes specific Method in PlayingActivity but Playing Activity which is under TabHost loses it's TabLayout

Is there AnyWay we can save Playing Activity to lose from it's TabLayout??

Was it helpful?

Solution

Just Found out that. Little bit of logic have saved my time.

Adding

finish();

inside the activity would done all my work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top