How to disable Android Navigation at res/navigation/nav_graph.xml - android

I have deleted the Fragment I created and its layout as I don't need it anymore.
But the Fragment keeps coming back except its layout (that is why I'm getting a missing layout.)
I saw it in the res/navigation/nav_graph.xml.
So I decided to delete the whole nav_graph.xml
On my third try, I included the deletion of the following implementation setup:
implementation 'androidx.navigation:navigation-fragment:2.3.2'
implementation 'androidx.navigation:navigation-ui:2.3.2'
But these two returned as well..
What is the trick of totally deleting them for good?

Remove the fragment in the activity xml that contains
android:name="androidx.navigation.fragment.NavHostFragment"
And if you still having the navgraph.xml, remove the startDestination property.
So then, select File -> Invalidate Caches/Restart -> Invalidate Cache & Restart

Related

Activity preview disappears when I add a fragment

A screenshot of the activity.xml
The dependencies i have added are the following:
implementation("androidx.fragment:fragment:1.5.5")
implementation("androidx.fragment:fragment-ktx:1.5.5")
I have tried to invalidate the cache, but that did not work.
I basically followed android documentation
Requested error

Problem migrating to Jetpack Compose. Trying to run the app from within Android Studio generates a wierd error

I've an application that uses Fragmnent Views with XML resources and I want to migrate it to Compose. Being the app quite big, I decided to temporarily have a mixed environment with Compose working together with the old XML resources, so I created a new Compose fragment and I succeeded to add the standard navigation action to navigate to it. The code builds successfully, but when I try to run the app I get the error of the picture below. It is particularly wierd because this error appears immediately, and not in the build panel, but in a popup dialog. Any hint ?
Ok, the documentation is not very clear, but in the end I found this:
"You can also include a ComposeView directly in a fragment if your full screen is built with Compose, which lets you avoid using an XML layout file entirely."
Being my app a hybrid one with XML navigation graphs, it looks like I need to define an XML resource anyway.
I hoped I cound avoid defining an XML layout, but it seems I need one for a fragment that has an old fashioned Activity as parent.
I'll post an update as soon as I discover something new
UPDATE
Adding an XML layout didn't fix the problem.
In fact the XML layout is not necessary. I don't really understand the cause of that error, but after cleaning a couple of times the project and clearing A.S. cache it disappeared. I succeeded to add a Compose Fragment to an old XML resources style app. The old navigation works without problems. Hope this post will help someone else save the time I have wasted...

Android Studio Navigation editor shows "Ambiguous type" on fragments

I am trying to create a navigation graph using the editor, but unfortunately it is showing "Ambiguous Type" on all my available fragments. I tried creating a new fragment, but still the same problem.
This issue results in the editor not showing the destinations that are available in the XML file.
I have cleaned the AS cache and restarted but this didn't fix anything. I started a new project from scratch and there everything seems to work correctly, so somehow there must be something in my project configuration that affects the navigation editor.
Did anyone experience something similar? Any clue what might be happening?
For me, it was because of conflict between two different types of fragment imports. I had this in my build.gradle
implementation "androidx.fragment:fragment:$androidx_fragment_version"
implementation "androidx.navigation:navigation-fragment-ktx:$androidx_navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$androidx_navigation_version"
Since navigation fragment is being imported through navigation-fragment-ktx, I removed the fragment
implementation "androidx.navigation:navigation-fragment-ktx:$androidx_navigation_version"
implementation "androidx.navigation:navigation-ui-ktx:$androidx_navigation_version"
Hopefully someone finds this helpful as well. I could not find answer anywhere else.
If you have multiple modules , Make sure the version of the imported Fragment is consistent
The dependencies above will cause Navigation ambiguous type
solution
In everyModule build.gradle
implementation "androidx.navigation:navigation-fragment-ktx:2.2.2"
implementation 'androidx.navigation:navigation-ui-ktx:2.2.2'
this will override default fragment version 1.1.0 --> 1.2.4
If you are using the modular architecture and the fragment which you have extended is inherits from one of the modules then you should use the navigation fragment dependency with those subsequent modules too.

android studio doesn't create navigation drawer activity

I just want to create a navigation drawer activity. When I Right click on app > new > activity > navigation drawer activity, nothing happens! it just creates a xml file in menu directory. i tried deleting android studio and user preferences files and reinstalling it, but still having the same problem. any suggestions?
First of all , you should create a new activity called navigation drawer activity , you just need to follow these steps : file > new > activity > navigation drawer activity . Then you can modify the xml content and create a navigation drawer like you want .
first create a new project with navigation drawer.
file > new project>navigation drawer activity. and then add content to the template
Make sure all navigation drawer activity files are safely deleted. This means all resource xml files. Also check whether the activity is created in AndroidManifest.xml, if it is remove the said activity.
After deleting all the xml and java files related to navigation drawer you even need to Delete these lines:
"implementation 'androidx.navigation:navigation-fragment:2.3.2'
implementation 'androidx.navigation:navigation-ui:2.3.2'"
in you app.gradle module,then try creating a navigation drawer activity named MainActivity2.
May be the android studio version you are using has problems. I think you are using android studio canary version. Try using stable version. If you are already using stable version then clear data and all the details and start project again.
Make sure that you have deleted all the files related to your previous navigation drawer activity. !!
And also remove the dependencies that were added during your first import.

appcompat_v7 and fragment_main.xml?

I've updated my eclipse and ADT Plugin from v22.3 to v22.6 recently and recognised some big changes. Whenever I create a new Android Application Project there appears a new appcompat_v7 library which wasn't present on v22.3 plugin and also a fragment_main.xml file which as I understand is meant to replace activity_main.xml file. Why is that? Why is the activity_main.xml file not preferred for activity layout directly anymore and why appcompat library is now included in every project as a necessity?
Is there a way to bring back the old way of creating projects without losing anything? By the way, I create projects compatible with Android versions from 2.2 to 4.4.
Fragment is useful for navigating through layouts of activity.for example if you have two different layout for portrait and landscape mode then you can simply navigate though the different fragments.
Secondly,
if you can not even get used to it,just remove the default code from activity_main.xml and and cut the fragment_layout.xml and paste it to activity_main.
Then delete the code related to fragment in MainActivity.java.Then delete the fragment_main.xml file.
Hope it will work.It worked for me.

Categories

Resources