K
K
Koshkasobaka2021-07-15 17:14:36
Android
Koshkasobaka, 2021-07-15 17:14:36

Is it possible to close an activity from a fragment?

It is conceived that when the fragment is closed, the activity is closed immediately. There are 2 options:
1) directly in the onDestroy() method of the fragment, call activity.finish()
2) Pass information to the activity so that it independently finish()

In the first option, there is less code, but it confuses the moment, do I give the fragment a lot of authority? Which option is acceptable?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-07-15
@Koshkasobaka

The total answer is no, you don’t need to do this, the fragment should be independent of the activity. If you need to close the application when the last fragment is closed, you must properly add fragments to the backstack.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question