Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getActivity() from Fragment is FragmentActivity not AppCompatActivity?

I have a BottomnavigationView in an AppCompatActivity that navigates between Fragments. For one of the Fragments, it's a MasterDetailFragment where you can search in that fragment and it will filter the data in the MasterFragment and you can click on the list to view the DetailFragment (all of this happens while the user is on one of the tabs in BottomNavigationView). I'm trying to use the new arch ViewModel to share the data between Master and Detail fragments: https://medium.com/@bharathkumarbachina/sharing-data-between-fragments-34afb6553380. It says to use getActivity() and share the viewmodel that way, but getActivity() is not getting the AppCompatActivity but instead is getting a FragmentActivity. Do I need to make a new MasterDetailFragmentActivity?

like image 707
waynejohn1110 Avatar asked Dec 03 '17 20:12

waynejohn1110


1 Answers

AppCompatActivity is a subclass of FragmentActivity. You can cast the FragmentActivity to AppCompatActivity after doing "instance of" check. https://developer.android.com/reference/android/support/v7/app/AppCompatActivity.html

like image 162
ElAman Avatar answered Nov 03 '22 02:11

ElAman