I'm making an app for 7" tablets. I'm following the example given here http://developer.android.com/guide/components/fragments.html.
There are two fragments.
TitlesFragment containing list
DetailsFragment containing webview to show result on click of an item in list
In landscape mode they are one next to another. Click in TitlesFragment list item will show details in the DetailsFragment. All in the same activity.
In portrait mode however, clicking in TitlesFragment opens a new Activity called DetailsActivity that has DetailsFragment which shows the details.
When he's on DetailsActivity switching to landscape mode finishes DetailsActivity and he's back on TitlesActivity where he will see the split view like explained before.
Problem now is -
Suppose he's on DetailsActivity in portrait mode. He starts a download and a dialog with active download progress bar is being shown. Now he switches to Landscape mode. The details activity finishes and my download dialog is gone. How can I handle this case?
This seems to be a common problem but I couldn't find a solution after searching. Can anyone help me?
Suppose he's on DetailsActivity in portrait mode. He starts a download
and a dialog with active download progress bar is being shown. Now he
switches to Landscape mode. The details activity finishes and my
download dialog is gone. How can I handle this case?
I'm assuming that the download continues(probably in a Service?!) even if the user finishes the DetailsActivity by switching to landscape. In this case you could let the landscape activity(which will hold both fragments) know about this and indicate somehow that the download is still in progress and an indicator should be shown. That indicator could be a dialog/ProgressBar on top of only the DetailsFragment for that position(so the user can still fully use the app) or on the entire screen.
Or you could lose the dialog and simply show a notification letting the use know a download is in progress without the need for the dialog. If the download is important and the user should wait this is not an option.
Related
When a RelativeLayout in an activity is clicked, it should open a fragment that shows a few checkboxes. The fragment should be in the center of the screen but should not cover the whole screen. The original contents activity should appear in the background but it should be grayed out. When I click 'OK' button in the fragment, the fragment should disappear and the original contents of the activity should appear normal (without graying out). I've tried writing a lot of code but what I get is completely different from what I have in mind. How can I achieve this functionality?
you should use DialogFragment , see this thread: https://developer.android.com/reference/android/app/DialogFragment.html
In my app, I display a custom Dialog (using DialogFragment), which on certain action causes another custom Dialog to be shown (using another DialogFragment). This all works fine. However when the "child" dialog is closed, I want to return to the parent dialog (which is closed/hidden when the child is displayed).
I do not want just display another instance of the same dialog, as I need to maintain states and behaviours of the parent prior to the child being open. Therefore I need to re-display physically the same dialog.
I can't seem to find a way of doing so.
Coming back to it as I now got a solution that seems to work. Apparently, using dialog directly will close the previous dialog when a new one is opened. Yet, when using DialogFragment, the previous fragment stays on screen when the new fragment is displayed. Then when the dialog on the new fragment is closed the previous fragment is still visible - exactly what I need.
I am using ActionBar Sherlock with a number of fragments.
The app I am building is a basic RSS reader much like the one shown here (http://www.youtube.com/watch?v=R_qR2glTTAs), except that there are multiple tabs for several different RSS feeds. When a tab is clicked, I replace the active fragment with the appropriate new fragment.
I am trying to get ActionBar animated refresh button functionality much like it is depicted in the YouTube video above. Basically, when the user clicks the refresh button, I expect the refresh button to rotate until the refresh is complete. If the user switches tabs while the current tab is refreshing, I want to show a refresh button that is NOT rotating.
The problem is: after I click on the refresh button and the button starts rotating, if I switch to another tab, I simply get a non-rotating refresh button on top of the rotating refresh button! This happens despite my calling menu.clear() and recreating the menu each time a tab is clicked. Interestingly, rotating the device causes the extra rotating refresh buttons to disappear.
Nothing I've tried seems to be able to stop the refresh animation when I change tabs! Any ideas why? I can post more of my code here if necessary.
I think the problem could be that you are animating and / or creating the menu inside your fragements... if this is the case do the things you want to do with your menu in the FragmentActivity
By the way, the effect you experience while rotating the screen is caused by the android architecture. Android always recreates the view if you are switching from portrait to landscape mode or the other way around.
According to the Google example here I developed an app based on fragments.
My main activity contains a listfragment of titles and, if it is created in landscape mode, a details fragment. If the app is startet in portrait mode, the main activity contains only the listfragment and, if a list item is clicked, start a new activity which shows the detailsfragment.
If I stay in either the portrait or landscape mode, everything works fine. But as soon as I change the orientation multiple problems occur.
1st problem: starting in portrait mode, then changing to landscape mode, the activity is added to the activity stack twice and I have to press the back button twice to close my app. I cant image this is the way Google wants this to work, so how do I avoid this?
2nd problem: when changing from landscape mode to portait mode, the list is shown and not the detailsfragment with the currently selected item. Therefore, all the user input in my detailsfragment is lost. This is just annoying and I don't know how to handle this. Do I have to care about the orientation change programmatically in every activity?
3rd problem: When I switch between n details in landscape mode, as soon as I change to portrait mode, I have to press the back button n times to close my add as the fragments are in the back stack (although they aren't visible any more). Do I have to clean the back stack myself in orientation change?
There is one thing about Activities. That is, when you change the orientation, the Activity restarts unless you do the following:
-First, add this in your manifest (inside the activity tag), so you will be able to tell the application what to do in case you change the orientation:
android:configChanges="orientation"
-Second, implement the following method in case you need to to something in case the orientation changes. If not, with the one before the user won't loose its data.
onOrientationChanged (int orientation)
I want to show a dialog (kind of splash screen) when my application is opened. Therefore I put a create and show dialog into onCreate(). The dialog opens indeed but first, the empty activity (white background) is shown.
There must be a possibility to prevent that empty screen to be shown? A lot of apps have a behaviour like that. I would like to have the dialog as the actual first screen to be shown to the user.
it would be better if we have code to see tasks taking time as per general solution
Android SplashScreen
Show spinning wheel dialog while loading data on Android
http://blog.iangclifton.com/2011/01/01/android-splash-screens-done-right/