I have the MainActvity class which contains a Tab (indicator as Tab)
Here is my code:-
public class MainActivity extends TabActivity {
TabHost tabHost;
Context context = MainActivity.this;
TabSpec spec;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost
.newTabSpec("Tab")
.setIndicator("Tab")
.setContent(
new Intent(this, MyActivityGroup.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)));
tabHost.setCurrentTab(0);
}
}
this internally calling MyActvityGroup which extends the ActvityGroup class as.
public class MyActivityGroup extends ActivityGroup {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// you van get the local activitymanager to start the new activity
View view = getLocalActivityManager().startActivity(
"ReferenceName",
new Intent(this, NewActivity.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
this.setContentView(view);
}
}
in NewActvity,java file i have done something like
public class NewActivity extends Activity {
Button btnGo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_activity);
btnGo = (Button) findViewById(R.id.btnStartActivity);
btnGo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(NewActivity.this, "Clicked", Toast.LENGTH_SHORT)
.show();
Intent intent = new Intent();
intent.setClass(getParent(), ButtonActivity.class);
startActivity(intent);
}
});
}
}
- now here this activity contains a button.
- I want to start the new activity in the same tab area on the click event of this button, but it start in the full screen mode. I am not able to see my tab any more.
- How can I start the activity in the current tab container.
- I there something wrong with my ActvityGroup class or I am not starting the activity in the proper manner..?
Use below code instead of your code, it will solve your problem.
MyActivityGroup.java
NewActivity.java
And Please see below link for more information.
Multiple Android Activities in a TabActivity