Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Please write below code for that, it will solve your problem.</p> <p>ActivityStack.java</p> <pre><code>private Stack&lt;String&gt; stack; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (stack == null) stack = new Stack&lt;String&gt;(); // start default activity push("FirstStackActivity", new Intent(this, Tab_SampleActivity.class)); } @Override public void finishFromChild(Activity child) { pop(); } @Override public void onBackPressed() { pop(); } public void push(String id, Intent intent) { Window window = getLocalActivityManager().startActivity(id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); if (window != null) { stack.push(id); setContentView(window.getDecorView()); } } public void pop() { if (stack.size() == 1) finish(); LocalActivityManager manager = getLocalActivityManager(); manager.destroyActivity(stack.pop(), true); if (stack.size() &gt; 0) { Intent lastIntent = manager.getActivity(stack.peek()).getIntent(); Window newWindow = manager.startActivity(stack.peek(), lastIntent); setContentView(newWindow.getDecorView()); } } </code></pre> <p>TabActivity.java</p> <pre><code>public class TabActivity extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tab_screen); TabHost tabHost = getTabHost(); Intent intent = new Intent().setClass(this, ActivityStack.class); TabHost.TabSpec spec = tabHost.newTabSpec("tabId").setIndicator("Temp", getResources().getDrawable(R.drawable.home)); spec.setContent(intent); tabHost.addTab(spec); Intent intent1 = new Intent().setClass(this, ActivityStack.class); TabHost.TabSpec spec1 = tabHost.newTabSpec("tabId").setIndicator("Temp", getResources().getDrawable(R.drawable.invoice)); spec1.setContent(intent1); tabHost.addTab(spec1); tabHost.setCurrentTab(0); } } </code></pre> <p>FirstActivity.java</p> <pre><code>public class FirstActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textView = new TextView(this); textView.setText("Tab Sample Activity "); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(getParent(), SecondActivity.class); ActivityStack activityStack = (ActivityStack) getParent(); activityStack.push("SecondActivity", intent); } }); setContentView(textView); } } </code></pre> <p>SecondActivity.java</p> <pre><code>public class SecondActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); TextView textView = new TextView(this); textView.setText("First Stack Activity "); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(getParent(), ThirdActivity.class); ActivityStack activityStack = (ActivityStack) getParent(); activityStack.push("ThirdActivity", intent); } }); setContentView(textView); } } </code></pre> <p>ThirdActivity.java</p> <pre><code>public class ThirdActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.main); } } </code></pre> <p>Add Below XML files into your res/layout folder.</p> <p>1) tab_screen.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:padding="3dp" &gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@android:id/tabs" android:layout_weight="1" /&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" /&gt; &lt;/RelativeLayout&gt; &lt;/TabHost&gt; </code></pre> <p>2) main.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>AndroidManifest.xml:-</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.android.tabsample" android:versionCode="1" android:versionName="1.0" &gt; &lt;uses-sdk android:minSdkVersion="8" /&gt; &lt;application android:icon="@drawable/ic_launcher" android:label="@string/app_name" &gt; &lt;activity android:name=".FirstActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".TabActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.LAUNCHER" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".ActivityStack" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".SecondActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;activity android:name=".ThirdActivity" android:label="@string/app_name" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.MAIN" /&gt; &lt;category android:name="android.intent.category.DEFAULT" /&gt; &lt;/intent-filter&gt; &lt;/activity&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>And see below link for more information with complete example.</p> <p><a href="http://androidcodeexamples.blogspot.in/2012/08/multiple-android-activities-in.html" rel="nofollow">Multiple Android Activities in a TabActivity</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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