Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fernandospr/android-navigation-abandon-fragment
Demonstrate a solution to call custom fragment logic when abandoning a fragment by pressing back or navigateUp.
https://github.com/fernandospr/android-navigation-abandon-fragment
Last synced: 5 days ago
JSON representation
Demonstrate a solution to call custom fragment logic when abandoning a fragment by pressing back or navigateUp.
- Host: GitHub
- URL: https://github.com/fernandospr/android-navigation-abandon-fragment
- Owner: fernandospr
- Created: 2020-03-09T11:35:17.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-03-09T11:52:47.000Z (almost 5 years ago)
- Last Synced: 2024-11-08T10:50:46.381Z (about 2 months ago)
- Language: Kotlin
- Homepage:
- Size: 122 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# android-navigation-abandon-fragment
This is a demo project to demonstrate a solution to call custom optional logic in your fragments when pressing back or navigateUp.
The demo contains three fragments:
* **AFragment**
* **BFragment**
* **CFragment****AFragment** and **CFragment** implement the `onAbandon()` method from the `AbandonListener` interface.
When pressing back or navigateUp, before going back, it'll call the `onAbandon()` method of the corresponding fragment, if the fragment implements the interface, otherwise it'll do nothing.In this demo project, both fragments just print their class name.
### Adding a New Fragment
1. Create a new fragment.
2. Add the new fragment to the navigation graph file: **nav_graph.xml**.
3. Add an action to reach the new fragment in the navigation graph.
4. Implement the navigation in the **MainActivity.kt** file.
5. If you want to perform custom logic in your new fragment when the user presses back or navigateUp, just implement the `AbandonListener` interface.