(Android) To call a function of activity called B in a fragment of activity called A

Asked 2 years ago, Updated 2 years ago, 77 views

MainActivity (B) has these methods. Therefore, MainActivity is using it to call another Fragment screen. ContentListActivity(A) has a ContentListFragment screen, and B to A's Fragment is called. However, in ContentListFragment, I want to call A's setFragment function

I want to show the login screen like below the comment

The above situation comes out. The reason for this is that the parents of ContentListFragment

Because it is ContentListActivity, the setFragment function of MainActivity cannot be called

That is, ((MainActivity)getActivity().setFragment(LoginFragment.newInstance ~..

I'm asking you this because I don't know the solution to this.

It's been a little over a year since I worked as a programmer in the equipment industry It's only been two months since I started mobile, but the developer who was developing the tool left in the middle I'm asking you because I don't know how to solve it because I have to develop additional parts that haven't been done since I came in and maintain them in the future. There's a story about using Otto, and startActivityForResult There are also stories such as mixing onActivityResult, but I'm struggling because I don't have an example that fits my situation. I look forward to your advice and advice.

android activity fragment otto switch-activity

2022-09-22 14:31

1 Answers

In the case of Android, a total of two methods are available.

One is using a library called Otto, or EventBus

For instructions on how to use http://gun0912.tistory.com/4 You can refer to it here or visit Github in person

I think it'll work.

I think the second method can be solved by using single tone globally.

For more information, refer to http://dreamlog.tistory.com/495 here.


2022-09-22 14:31

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.