[Android] Only fragments are finished

Asked 2 years ago, Updated 2 years ago, 58 views

Hello, I'm a beginner at Android.

We have created and used fragments to eliminate the hassle of moving from the main activity to other activities. I want to show you the activity screen again.

Is there any other way to get rid of the fragment than to adjust it in the main activity?

I just want to get rid of the fragment itself. Help me

android fragment

2022-09-22 19:38

2 Answers

If you add a fragment in MainActivity, in Fragment
You can call functions in MainActivity as follows:

When MainActivity has the following function,

...
public void destroyFragment() {
...
}
...

You can call in the following way.

((MainActivity)getActivity()).destroyFragment();


2022-09-22 19:38

Yes, you need to access Fragment Manager to remove the fragment.

I think you are managing Fragment Manager in the main activity To access at the Fragment level, you may need to share the FragmentManager object or the MainActivity object.

However, there is a Event Bus library that calls between Fragment and Activity.

http://gun0912.tistory.com/4 to.


2022-09-22 19:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.