I am using HoloEverywhere + ActionBar Sherlock + HoloEverywhere's sliding menu addon. When clicking an item in the sliding menu, I start various activities.
My problem is to implement what Cyril Mottier talks about in his article about Prixing's SlidingMenu:
- overriding activity transitions (that's the easy part)
- saving/restoring the menu state between activities (that's what I can't manage to do): currently the menu disappears and it does not feel right. I would like to save the menu state and when the next activity starts, restore that state (and animate the close of the menu for instance)
Cyril talks about using the view's saveHierarchyState, ...:
The Activity transition in the Prixing application relies on the exact same technique the Android framework uses to restore an Activity after it has been destroyed in low memory conditions. As a result, everytime a new Activity needs to be opened, we save the the interesting part of the current UI state using View#onSaveInstanceState()/View#saveHierarchyState(SparseArray<Parcelable>) and re-apply it to the newly created Activity thanks to View#onRestoreInstanceState(Parcelable)/View#restoreHierarchyState(SparseArray<Parcelable>)
However I have trouble seeing how to implement that? Would anyone have any clue?
My activities all inherit from a base activity class which keeps its instance of the sliding menu.
See SlidingMenu issue
You can update code from the last version of SlidingMenu to same module of HoloEverywhere.
Or wait 1.4.3, where this module will be updated by me.
Related
I watched some videos for navigation drawer in android studio .. some people started from an empty activity and other used Navigation Drawer Activity from the Starter ..
So what's the difference ?
And what activity i have to implement ?
(my first activity is splash screen and all others activity will be added as new activity, btw I'm doing a football application so advice me <3)
Android studio provides you some templates as starting point with boilerplate code to get you started quickly on your project.
If you select DrawerActivity, It will create one of the templates, you can use which has all the boilerplate implementation for the Drawer Menu.
On the other hand, if you select EmptyActivity, It will just an create an activity with nothing in it (mostly blank or HelloWorld TextView in it, depending on studio versions).
By the way, you can always create an EmptyActivity and add things gradually like drawermenu etc in it if you prefer this way.
Empty activity : It has just the white screen and nothing else.
NavigationDrawer activity : Empty screen integrated with Navigation Drawer
I found a lot of informations about the setRetainInstance method, but I'd like to know how to implement this method in a Navigation Drawer Activity?
I basically have:
An Activity, that contains...
a NavigationDrawerFragment, that contains...
a TopLevelMapFragment (showing Google Maps).
My aim is to prevent a reload of the whole maps and its tracks when the user rotates the screen. What is the basic concept of setRetainingInstance in an Navigation Drawer Activity? Do I have to call setRetainingInstance(true) in the NavigationDrawerFragment AND the TopLevelMapFragment?
I finally found the solution to my Problem:
When I created the Navigation Drawer Activity, I relied on the default Navigation Drawer Activity-template of Android Studio. In this template, the FragmentTransaction-replace method is called each time the user clicks on an item in the Navigation Drawer. Problem: the replace-method destroys all the fragments that are in the specified container.
So if you want to keep your fragments alive, don't ever use the replace method. You have to use the methods add, show and hide instead.
In addition, I call the setRetainInstance(true)-method in my Google Maps-Fragment, so that the fragment stays alive when the user rotates the screen for example.
I'm used to using a 3rd party library for implementing a navigation drawer (sliding menu) in Android, but I want to use the native version from now. I went through the tutorial (http://developer.android.com/training/implementing-navigation/nav-drawer.html) which is pretty straight forward.
I typically extend the 3rd party navigation drawer to each activity by defining the configuration in a base class. The new nav drawer, however, swaps fragments in and out, which my research indicates is the standard way of managing your displays.
This seems fine, but my app has a fairly complex hierarchy of pages and navigation. Like most apps, it contains more fragments than just the ones in the menu.
So if I have 3 nav drawer items for fragments A, B, and C, and I can only load fragment D from fragment C, do I handle that navigation logic in the activity where I configure the nav drawer? It seems like kind of a nightmare to have one container to swap out an indefinite number of fragments, especially if the work flow is deep.
From what I can gather on Stack, there seem to be a lot of people who are familiar with extending a 3rd party drawer in each Activity, but when they switch over to the native version there is confusion.
So to summarize, I understand the fragment swapping aspect of the navigation. I just don't understand how the rest of the work flow navigation would work, say if I had several detail screens below a nav item fragment. If anyone can give me some hints on how best to approach this scenario, maybe I can experiment and post some code for future readers.
For navigation in Android there is always one thing you have to remember:
If you stay on the same level of the navigation hierarchy, for
example when swiping through pages, you use Fragments.
When you move up and down in the navigation hierarchy, for example
going to a detail view, you would start a new Activity and displayed the
Fragment with the detail content in it.
A NavigationDrawer is used for top level navigation in your app to quickly navigate between different parts of your app. It's kind of like a main menu. With that in mind you need to determine if a NavigationDrawer makes sense in your app. It's all about how the user should navigate through the content. If there is just one path for the user to follow for example if you start out with just one screen and from then on the user can just go deeper and deeper in the navigation hierarchy from one detail view to the next than a NavigationDrawer does not make much sense. But if there are multiple paths the user can take that lead into different, independent parts of your app without one dedicated start screen on which everything else depends than a NavigationDrawer sounds pretty reasonable.
You can look at Google apps like Gmail, Drive or Google+ to see how a NavigationDrawer is supposed to be used.
I have a Activity A, a ListFragment P and 2 Fragments Q and R.
When the app is launched, A is created, which loads P. Based on what user clicks, it is replaced by Q or R.
Now by referencing this tutorial, I have implemented a Navigation Drawer which shows certain items to the user. However, since I have implemented the Navigation Drawer in the Activity, it shows for all the Fragments.
I want it to be only available to P.
(Very much similar to Googles Gmail app. When the user is on the main screen - the drawer is present. When user taps to open an email, the drawer changes to back button)
I am not sure how to translate the above code. Any help is appreciated.
I solved this issue by simply overriding the up carat behavior by calling the mDrawerToggle.setDrawerIndicatorEnabled(enable) and passing the boolean enable or disable as needed.
(The fragments where I didn't want the drawer to show called this method with false and where I wanted the drawer to be shown called this method with true. I put the call inside the onResume() of the respective fragment for obvious reasons.)
This works exactly like I want, and I did not have to change the design of my project :).
What you can do is create a new FragmanetActivity S and replace Q and R accordingly. If you are app is for Android 3.0 lower user ActionBarActivity create a actionbar and set its setDisplayHomeAsUpEnabled(true). As the new FragmentActivity will have new layout there will be no NavigationDrawer.
I want to create a app with a menu at the bottom of the screen. This menu should be visible any time the app is started.
Im working with fragments, so the menu is one fragment.
So I have only one Activity as controller which loads different fragments above the menu fragment.
Because I want to create clean code, i dont know how to solve the problem that the Activity class is too big.
In other words, i want to create different controller within the same activity. How to do that?
Is there another approach to solve this issue?
You should be using the split action bar This allows you to put the Actions and overflow menu on the bottom of the screen. I believe you can use Action Bar Sherlock for backwards compatibility to older versions of Android. See their site for detail.
Another possibility is to look into using fragments with the ViewPager . Here is a library that works with compatability as well ViewPageIndicator . Here is a blog post , like I indicated in my comment I got this working with the tabs showing at the bottom and the pages above.