Why isn't the Fragment shown in Navigation? - java

When starting the app, I see neither the recycle view nor the normal fragment. I'm sure that the Navigation switch the fragments but I do not see results. But when I use the saveInstantState I can get the Recycle view to work but I can't switch fragments anymore...
Any help would be great.
Main.java
public class MainActivity extends AppCompatActivity {
MusicStoreService music;
private DrawerLayout drawerLayout;
private NavController navController;
private NavigationView navigationView;
private AppBarConfiguration appBarConfiguration;
public MainActivity() {
super(R.layout.main);
}
#Nullable
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
music = new MusicStoreServiceMock();
setContentView(R.layout.main);
Toolbar toolbar = findViewById(R.id.toolbar);
// make sure you import androidx.appcompat.widget.Toolbar !
setSupportActionBar(toolbar);
drawerLayout = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.nav_view);
NavHostFragment navHostFragment = (NavHostFragment)
getSupportFragmentManager()
.findFragmentById(R.id.nav_host_fragment_container);
navController = navHostFragment.getNavController();
Set<Integer> topLevelDestinations = new HashSet<>();
topLevelDestinations.add(R.id.productListFragment2);
topLevelDestinations.add(R.id.helloworld);
appBarConfiguration = new AppBarConfiguration.Builder(topLevelDestinations)
.setOpenableLayout(drawerLayout)
.build();
NavigationUI.setupWithNavController(toolbar, navController,
appBarConfiguration);
NavigationUI.setupWithNavController(navigationView, navController);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.setReorderingAllowed(true)
.add(R.id.nav_host_fragment_container, ProductListFragment.class, null)
.commit();
System.out.println();
}
}
public MusicStoreService getMusic() {
return music;
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_scrollFlags="scroll|enterAlways" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="#navigation/nav_graph" />
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="#menu/nav_menu"
/>
<!-- attribute app:menu isn't mentioned in the documentation! -->
</androidx.drawerlayout.widget.DrawerLayout>
menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:title="MusicStore">
<menu>
<item
android:id="#+id/productListFragment2"
android:title="Products" />
</menu>
</item>
<item android:title="Service">
<menu>
<item
android:id="#+id/helloworld"
android:title="Your Account" />
</menu>
</item>
</group>
</menu>
nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nav_graph"
app:startDestination="#id/productListFragment2">
<fragment
android:id="#+id/productListFragment2"
android:name="musicstore.fragments.ProductListFragment"
android:label="Product List" >
<action
android:id="#+id/action_productListFragment2_to_mainActivity2"
app:destination="#id/mainActivity2" />
</fragment>
<fragment
android:id="#+id/helloworld"
android:name=".musicstore.fragments.helloworld"
android:label="Your Account"
tools:layout="#layout/fragment_helloworld" />
<fragment
android:id="#+id/productDetailFragment2"
android:name="musicstore.fragments.ProductDetailFragment"
android:label="ProductDetailFragment" />
<activity
android:id="#+id/mainActivity2"
android:name="musicstore.MainActivity"
android:label="activity_main"
tools:layout="#layout/activity_main" />
</navigation>
Recycle view fragment:
public class ProductListFragment extends Fragment {
RecyclerView recyclerView;
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
System.out.println("Hello");
View v = inflater.inflate(R.layout.product_list_fragment, container, false);
recyclerView = (RecyclerView) v.findViewById(R.id.productlist_recycler);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
recyclerView.setLayoutManager(layoutManager);
return v;
}
#Override
public void onViewCreated(#NonNull View view, #Nullable Bundle savedInstanceState) {
ProductListAdapter pld = new ProductListAdapter(((MainActivity) getActivity()).getMusic(),getContext(),new ClickerListener());
recyclerView.setAdapter(pld);
}
Simple fragment:
public class helloworld extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_helloworld, container, false);
}
}

Related

Button does not have a NavController set

I started writing an andoid app game but am already struggling with the navigation.
I have a Main Activity that is also the defaultNavHost of my navigation. It displays my Main Fragment, which has 3 buttons. Each should be leading to a different Fragment but that is where the problem occurs.
When clicking any of the buttons, I get the Error "MaterialButton [...] does not have a NavController set."
Example of one of the onClick() methods in my mainFragment:
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container,
#Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
view.findViewById(R.id.olympia_button).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Navigation.findNavController(view).navigate(R.id.nav_main_to_olympia);
}
});
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
part of my nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nav_graph"
app:startDestination="#id/mainFragment">
<fragment
android:id="#+id/mainFragment"
android:name="com.example.spieleolympiade.ui.main.MainFragment"
android:label="fragment_main"
tools:layout="#layout/fragment_main" >
<action
android:id="#+id/nav_main_to_olympia"
app:destination="#id/olympiaFragment" />
<action
android:id="#+id/nav_main_to_players"
app:destination="#id/playersFragment" />
<action
android:id="#+id/nav_main_to_halloffame"
app:destination="#id/hallOfFameFragment" />
</fragment>
<fragment
android:id="#+id/olympiaFragment"
android:name="com.example.spieleolympiade.ui.olympia.OlympiaFragment"
android:label="fragment_olympia"
tools:layout="#layout/fragment_olympia" >
<action
android:id="#+id/nav_olympia_to_main"
app:destination="#id/mainFragment" />
</fragment>
I have read online on posts such as this one that the official solution to this problem would be
NavHostFragment navHostFragment =
(NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment);
NavController navController = navHostFragment.getNavController();
now I don't understand:
I can't use the getSupportFragmentManager() function in my fragment where I need it
If i put that code in my mainActivity where I can use getSupportFragmentManager(), what do I then do with the navController variable that I get out of that.
Can you use below code for navigation from your fragment
NavHostFragment.findNavController(this).navigate(R.id. nav_main_to_olympia)

Home button not working after being pressed

I want to access my home page after being pressed. The problem is that after the home button is pressed, you will not be able to go back to it. Despite using the return root function, it still doesn't allow me to access the page after being clicked. This picture shows how I am still pressing on the home button but nothing comes up.
Does anyone know the solution to this problem?
Here is my HomeViewModel:
public class HomeViewModel extends ViewModel {
private MutableLiveData<String> mText;
public HomeViewModel() {
mText = new MutableLiveData<>();
mText.setValue("This is home");
}
public LiveData<String> getText() {
return mText;
}
}
Here is my HomeFragment:
public class HomeFragment extends Fragment {
private HomeViewModel homeViewModel;
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
homeViewModel =
new ViewModelProvider(this).get(HomeViewModel.class);
View root = inflater.inflate(R.layout.fragment_home, container, false);
final TextView textView = root.findViewById(R.id.home_fragment);
homeViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
#Override
public void onChanged(#Nullable String s) {
textView.setText(s);
}
});
return root;
}}
Here is my MainDashboard Activity:
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:fitsSystemWindows="true"
app:itemIconTint="#drawable/bottom_navigation_selector"
app:itemTextColor="#color/darker_grey"
app:labelVisibilityMode="labeled"
app:layout_constraintBottom_toBottomOf="#id/fragment2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:paddingBottom="38sp"
app:layout_constraintTop_toBottomOf="#id/fragment2"
app:menu="#menu/bottom_nav_menu" />
<fragment
android:id="#+id/fragment2"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="#navigation/mobile_navigation"
tools:layout_editor_absoluteX="200dp"
tools:layout_editor_absoluteY="358dp" />
Here is my MainDashboardClass:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main__dashboard);
getSupportActionBar().hide();
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation_view);
NavController navController = Navigation.findNavController(this, R.id.fragment2);
NavigationUI.setupWithNavController(bottomNavigationView, navController);
Here is my Navigaion Graph:
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mobile_navigation"
app:startDestination="#+id/navigation_home2">
<fragment
android:id="#+id/navigation_account"
android:name="com.login.diamondcharnea.ui.Dashboard_Elements.Account.AccountFragment"
android:label="account.layout"
tools:layout="#layout/fragment_account" />
<fragment
android:id="#+id/navigation_favorites"
android:name="com.login.diamondcharnea.ui.Dashboard_Elements.Favorites.FavoritesFragment"
android:label="favorites.layout"
tools:layout="#layout/fragment_favorites" />
<fragment
android:id="#+id/navigation_home2"
android:name="com.login.diamondcharnea.ui.Dashboard_Elements.home.HomeFragment"
android:label="Home.layout"
tools:layout="#layout/fragment_home" />
<fragment
android:id="#+id/navigation_browse"
android:name="com.login.diamondcharnea.ui.Dashboard_Elements.Browse.BrowseFragment"
android:label="Browse.layout"
tools:layout="#layout/fragment_browse" />
<fragment
android:id="#+id/navigation_bag"
android:name="com.login.diamondcharnea.ui.Dashboard_Elements.bag.BagFragment"
android:label="Bag.layout"
tools:layout="#layout/fragment_bag" />
</navigation>
And here is my BottomNavMenu:
<item
android:id="#+id/navigation_home"
android:icon="#drawable/diamond"
android:title="#string/title_home"
/>
<item
android:id="#+id/navigation_browse"
android:icon="#drawable/iconfinder_search_172546"
android:title="Browse" />
<item
android:id="#+id/navigation_bag"
android:icon="#drawable/shopping_bag"
android:title="#string/bag" />
<item
android:title="#string/favorites"
android:id="#+id/navigation_favorites"
android:icon="#drawable/heart" />
<item
android:title="#string/account"
android:id="#+id/navigation_account"
android:icon="#drawable/user" />
</menu>

Snackbar.setAnchorView(NOTWORKING);

This code:
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CoordinatorLayout root = findViewById(R.id.root);
BottomNavigationView navView = findViewById(R.id.bottom_navigation);
Snackbar.make(root, "Text", Snackbar.LENGTH_LONG).setAnchorView(navView).show();
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Main content -->
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:menu="#menu/bottom_navigation_menu" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
is not working for me. The Snackbar is still showing underneath the bottom navigation view. Is there something I'm missing or is this a bug?

How to set menu to an AppBarLayout

I'm new to programming, and I want to add a settings menu button.
Like on the picture, my app doesn't show the three dots button.
MainActivity.java :
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.settings, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.vueSatellite:
Toast.makeText(this, "Hi", Toast.LENGTH_SHORT).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.viewpager.widget.ViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?actionBarSize"
android:padding="#dimen/appbar_padding"
android:text="#string/app_name"
android:textColor="#color/colorAccent"
android:textAppearance="#style/TextAppearance.Widget.AppCompat.Toolbar.Title" />
<com.google.android.material.tabs.TabLayout
android:id="#+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/White"
app:tabTextColor="#color/colorAccent"/>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
settings.xml :
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="#+id/vueSatellite"
android:title="#string/item_vue_satellite"
app:showAsAction="never"/>
</menu>
What is my mistake ?
Or what do I have to add?
Tell me if there is missing information like the file AndroidManifest.xml for example.
Thanks
In your Activity just add
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Hope it works.

Toolbar menu being cleared after being set (When activity is started)

Toolbar menu is inflated in fragment but then cleared later.
When activity is first created (or rotated) the toolbar menu is inflated properly in the fragment, but then gets cleared before it can be displayed.
I set the toolbar menu in my fragment's onActivityCreated, and it stays set through onResume in the activity. The next call I've found is in onCreateOptionsMenu in the activity, but at this point toolbar.getMenu().size() = 0
Somewhere between onResume and onCreateOptionsMenu the toolbar menu is getting reset.
Edit:
I'm not sure what is necessary to reproduce it, but here is all(?) of the relevant code.
Activity:
private Toolbar toolbar;
private DrawerLayout drawer;
private ActionBarDrawerToggle toggle;
private FloatingActionButton fab;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.drawer_main);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
fab = findViewById(R.id.main_fab);
drawer = findViewById(R.id.drawer_layout);
toggle = new ActionBarDrawerToggle(this, drawer,toolbar,R.string.nav_drawer_open,R.string.nav_drawer_close);
drawer.addDrawerListener(toggle);
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
if (savedInstanceState == null) {
showFragment(ScheduleFragment.newInstance());
}
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if(toggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
CharSequence retainTitle = toolbar.getTitle();
super.onPostCreate(savedInstanceState);
toggle.syncState();
toolbar.setTitle(retainTitle);
}
Fragment:
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
toolbar = ((MainActivity)getActivity()).getToolbar();
setMenuAction(MENU_ACTION_DELETE);
}
protected void setMenuAction(int menuAction) {
Log.d(logger, "setting the menu");
switch(menuAction) {
case MENU_ACTION_DELETE:
toolbar.getMenu().clear();
toolbar.inflateMenu(R.menu.menu_delete);
break;
case MENU_ACTION_NONE:
Log.d(logger, "clearing menu");
toolbar.getMenu().clear();
break;
}
}
Layouts:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout">
<include
layout="#layout/activity_main"/>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header"
app:menu="#menu/menu_nav" />
</android.support.v4.widget.DrawerLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|snap|enterAlways"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/main_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:src="#drawable/ic_baseline_add_24px"
android:layout_margin="16dp" />
<include layout="#layout/content_main"/>
</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="#layout/activity_main">
<FrameLayout
android:id="#+id/fragmentHolder"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
The problem in my current code as posted was the line setSupportActionBar(toolbar);
This was not needed, and was in fact causing the troubling lifecycle problems stated above.

Categories

Resources