0

tabbed activity overrides by activity when follow android tabbed activity.

I am a newbie in android. I am learning to include some activities on different tabs. however, the activity gets fullscreen and override the main tab

// TabMain.java 
public class TabMain extends AppCompatActivity {

  .......
}
// SectionsPagerAdapter.java extends FragmentPagerAdapter
@Override
    public Fragment getItem(int position) {
        switch (position){
            case 1:
                FragmentTab1 tab1 = new FragmentTab1();
                return tab1;
                default:
                    return PlaceholderFragment.newInstance(position + 1);
        }
    }
public class FragmentTab1 extends Fragment {

    @Override
    public View onCreateView(
            @NonNull LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.galery_main_layout, container, false);
        Intent intent = new Intent(getActivity(), UploadMain.class);
        getActivity().startActivity(intent);

        return root;
    }
}

the UploadMain.java implement Activity

<application
        android:icon="@drawable/icon"
        android:label="@string/app_name">
        <activity
            android:name=".TabMain"
            android:label="@string/title_activity_tab_main"
            android:theme="@style/AppTheme.NoActionBar">

        </activity>
        <activity
            android:name=".FdActivity"
            android:configChanges="keyboardHidden|orientation"
            android:label="@string/app_name"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".UploadMain"
            android:configChanges="keyboardHidden|orientation"
            >

        </activity>
    </application>

I am expecting for the upload main class to be inside tab2

TabMain | Tab 1 (other activity) | Tab 2 (UploadMain)

mambo
  • 25
  • 1
  • 6
  • It's best to think of an Activity as a single screen of your application (not always true, but it's still a good way of thinking about them). For sections of your screen (including "tab" content), use `Fragment`s or `View`s. – PPartisan Oct 22 '19 at 16:17
  • [TabActivity](https://developer.android.com/reference/android/app/TabActivity.html) has been deprecated for some time now - best switch over to one Activity plus Fragments, see for example [this SO post](https://stackoverflow.com/questions/7599816/creating-tabs-using-fragments-now-that-tabactivity-is-deprecated) – Bö macht Blau Oct 22 '19 at 16:22
  • BTW AppCompatActivity does not extend TabActivity so it can't work the way you want it to. – Bö macht Blau Oct 22 '19 at 16:23

2 Answers2

0

You can't have a Activity inside a ViewPager, it must be a fragment.

And also, when you start activity, like this,startActivity(intent) it will not replace the previous screen or activity, it will just create a new activity with a new layout, having the previous activity paused (and also sometimes stopped) until you close the previous activity. You need to learn more about activity and fragment lifecycles

touhid udoy
  • 4,005
  • 2
  • 18
  • 31
-1

Your FragmentTab1 starts a new Activity instead of only replacing the View inside your framelayout you start a whole new Activity. Your Code belongs inside the class Fragmenttab1 and the line Intent intent = new Intent(getActivity(), UploadMain.class); getActivity().startActivity(intent);

should be removed

Dominik Wuttke
  • 535
  • 1
  • 4
  • 12