First of all, I'm new in Android.
I tried to use Fragments with Bottom-Navigation and my question is, every time I change my Fragment
(for example, fragment1 -> fragment2) my tabs doesn't change with the change in Fragment
and everything I did in fragment1 is not saved.
To make it clearer:
I got bottom navigation bar/tab (I'm not sure what to call it). In that bar I have got 3 tabs (For example; chats, profile and contacts).
- First I go to the profile tab and change something (for example my name). Then I go to the contacts and when I come back to the profile tab, the name that I changed earlier isn't there. It goes back to the information previously saved.
How can I save this information? Do I have to write all the information in the database and read it every time I open the profile fragment? Is it even possible?
Or can I save it in the SharedPreference
or somewhere else? Please give me some advice with example code so that I can understand..
For example, I have a button in profile fragment and with this button it will change to chat fragment.
FragmentManager().beginTransaction().replace(R.id.frame,fragmentTwo).commit();
When I do this, my fragment changes to another fragment, but my tabs in navigation bar doesn't change and it remains in the profile tab.
- Last Question. If I change my fragment what kind of function it does run? I mean there are
onCreate
,onCreateView
,onActivityCreated
etc. and how can I understand how every function runs. After each other with that sequence.
Please help. I'm stuck for weeks.