logo
down
shadow

Show confirmation on back/up in Fragment with Navigation Architecture Component


Show confirmation on back/up in Fragment with Navigation Architecture Component

By : user2185575
Date : November 22 2020, 04:01 AM
help you fix your problem As of androidx.appcompat:appcompat:1.1.0-beta01, in order to intercept the back button with navigation component you need to add a callback to the OnBackPressedDispatcher. This callback has to extend OnBackPressedCallback and override handleOnBackPressed. OnBackPressedDispatcher follows a chain of responsibility pattern to handle the callbacks. In other words, if you set your callback as enabled, only your callback will be executed. Otherwise, OnBackPressedDispatcher will ignore it and proceed to the next callback, and so on until it finds an enabled one (this might be useful when you have more than one callback, for instance). More info on this here.
So, in order to show your dialog, you would have to do something similar to this:
code :
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  super.onViewCreated(view, savedInstanceState)

  val callback = object : OnBackPressedCallback(true /** true means that the callback is enabled */) {
    override fun handleOnBackPressed() {
        // Show your dialog and handle navigation
    }
  }

  // note that you could enable/disable the callback here as well by setting callback.isEnabled = true/false

  requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, callback)
}
navController.addOnDestinationChangedListener { navController, destination ->
  if (destination.id == R.id.destination) {
    // do your thing
  }
}


Share : facebook icon twitter icon
How to disable UP in Navigation for some fragment with the new Navigation Architecture Component?

How to disable UP in Navigation for some fragment with the new Navigation Architecture Component?


By : DIVYA
Date : March 29 2020, 07:55 AM
Does that help First, add attributes app:popUpTo='your_nav_graph_id' and app:popUpToInclusive="true" to the action tag.
code :
<fragment
    android:id="@+id/signInFragment"
    android:name="com.glee.incog2.android.fragment.SignInFragment"
    android:label="fragment_sign_in"
    tools:layout="@layout/fragment_sign_in" >
    <action
        android:id="@+id/action_signInFragment_to_usersFragment"
        app:destination="@id/usersFragment"
        app:launchSingleTop="true"
        app:popUpTo="@+id/main_nav_graph"
        app:popUpToInclusive="true" />
</fragment>
findNavController(fragment).navigate(SignInFragmentDirections.actionSignInFragmentToUserNameFragment())
Android architecture component navigation: toolbar back button missing, back not working

Android architecture component navigation: toolbar back button missing, back not working


By : user2015990
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm trying the jetpack navigation and can't show the navigation back button when I move to a new fragment. , Edit: Your DetailFragment contains the line
code :
DataBindingUtil.setContentView<FragmentDetailBinding>(requireActivity(),
    R.layout.fragment_detail)
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".views.NavActivity">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="?attr/actionBarSize"
        android:elevation="4dp"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:layout_width="match_parent"/>

    <fragment
        android:id="@+id/navigation_graph"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:navGraph="@navigation/navigation_graph"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_nav_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/menu_bottom_nav" />
</LinearLayout>
Back navigation after deep link by navigation architecture component

Back navigation after deep link by navigation architecture component


By : user3496605
Date : March 29 2020, 07:55 AM
How do I disable back navigation and remove the back arrow on a Fragment, using Android Jetpack's Navigation component?

How do I disable back navigation and remove the back arrow on a Fragment, using Android Jetpack's Navigation component?


By : willie
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You need to remove fragment1 from back-stack when navigation to fragment2
fragment1
code :
<fragment
android:id="@+id/fragment1"
android:name="packagenameforFragment1"
android:label="fragment1"
tools:layout="@layout/fragment_1" >
<action
    android:id="@+id/action_Fragment1_to_Fragment2"
    app:destination="@id/Fragment2_id"
    app:launchSingleTop="true"
    app:popUpTo="@+id/your_MainGraph_id"
    app:popUpToInclusive="true" />
findNavController(fragment).navigate(R.id.action_Fragment1_to_Fragment2)
val appBarConfiguration = AppBarConfiguration
        .Builder(R.id.your_fragment2_id,R.id.any_other_ids_you_want)
        .build()
setupActionBarWithNavController(this, yourNavController, appBarConfiguration)
Navigation Architecture Component - how to set/change custom back or hamburger icon with navigation controller?

Navigation Architecture Component - how to set/change custom back or hamburger icon with navigation controller?


By : Sam Wilton
Date : March 29 2020, 07:55 AM
Related Posts Related Posts :
  • Getting a string value from the strings.xml resource file and set it in an interface class
  • Flutter, sign with both debug keys and release keys on Android
  • will an android service run code from the Xamarin Forms Project even when the app is closed?
  • Change boolean values on listviewitems in firebase
  • Android Studio 3.2.1: mixing versions can lead to runtime crashes when connect firebase
  • FCM migration without losing the old token
  • Change reported Version Number in Fabric Crashlytics
  • lateinit property mMap has not been initialized
  • Android - PWA does not open in standalone mode with service worker
  • Does LeakCanary has callback?
  • How to disable back button after splash screen in React Native
  • Assets Folder Not Including HTML Files In NativeScript Android Build
  • Dagger: What if I *WANT* a new instance every time?
  • How to get mailto working on android chrome?
  • SSO web login in android app with customtabs
  • how to make specific button side curved
  • remove item onlongclick from listview
  • header image alignment coming wrongly in NavigationView android
  • How to add many spaces after the text in TextView
  • how to set "Back Button" , closing activies except main activity in android?
  • Unable to run emulator on Android Studio || Windows 10
  • How can I achieve this requirement using Rx Java
  • How to tilt a Node(or TransformableNode)object downwards in Sceneform(Ar Core)?
  • When to use RTL and LTR?
  • How to create a tab view (category) similar to instagram's explore tab
  • Glide, RecyclerView: Glide returns the same picture over and over again even with different data inputs
  • how to stop open activity while splash screen killed
  • Changing the Color of the Dynamically loaded Buttons onclick
  • Listview: Add arrows as dividers
  • How to find the corresponding maven artifact/gradle module of an Android class from the API Docs?
  • ZXing 3.6.0 in portrait mode?
  • Can't use Subversion command line client: svn The path to the Subversion executable is probably wrong android
  • how to set spinner list value first position showing empty
  • When using PersistableBundle in onCreate, it shows me a blank page
  • Failed to resolve Bintray dependency
  • jacoco code coverage not working for Android applications
  • How to change the color of the Android scroll bumper
  • Why run Handler in main Looper thread
  • Android Studio combined chart crashes
  • Setting suggested width and height to a custom view in android
  • How to set input type and format in EditText using kotlin?
  • how to define Android Oncreate optionmenu
  • Exception on orientation change from two-pane mode to one-pane mode
  • How to access members of nested struct and assign them the values read from device tree?
  • How to measure upload progress of a huge String with Retrofit 2?
  • Runtime app localization doesn't work with app bundles
  • How create View and Putting TextView inside it in kotlin
  • how to integrate app action using actions.xml?
  • ConstraintLayout - center TextView in the root but don't override Button
  • Android Studio Text not conforming to layout_margin when I run App on Emulator
  • verifyReleaseResources apk release - react native
  • My app is not visible in share dialog even with intent filters in place
  • How to use cache or local storage?
  • Unhandled Exception in Recycler view xamarin
  • Android Workmanger PeriodicWorkRequest API work only once?
  • Using Touch ID or Face ID without storing user biometrics
  • React Native 3 button and 3 Modal
  • Token Expiration after 1 Hour in Authentication using Retrofit 2 and Logging Interceptor
  • JNI DETECTED ERROR IN APPLICATION: JNI NewGlobalRef called with pending exception java.lang.ClassNotFoundException:
  • /bin/sh: adb: command not found
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org