I have 3 activities in sequence.
Order Details Screen -> Images List Screen-> Image View Screen
For Order Details, I didn't provide parentActivityName
For Images List Screen, I provided
android:parentActivityName=".activities.OrderDetails"
For Images View Screen, I provided
android:parentActivityName=".activities.OrderDetails"
But when i click back button while in Image View screen, it is still taking me to the previous activity only (Images List) which is in the Activity stack generally.
Whereas I was expecting it to come back to OrderDetails Screen because I mentioned android:parentActivityName=".activities.OrderDetails".
I would like to know why it is overriding the parentActivityName, and how to make it work as expected.
Related
I am creating a book app in which i have many text images around 60. I want to move back and forth on click of forward and backward button, just to give changing pages feel where user can read the pages.
Also i am not sure whether to use fragements or a whole activity to show the images.
If the content is static, I do believe the best approach would be to make an array with pointers to each image, then, have an activity that loads the image and make an animation to "swap" pages.
Also, how is the hierarchy you are using? Does the user use the hardware back button to go back pages, or are you using left/right buttons to swap pages.
In the first case, do note that you could create a lot of activities that serve no purpose.
So:
onCreate() Start the program, do your styles and etc. then load the image[0]
onResume() Update the image, do the transition effect
onPause() Save the index of the image array, and the direction the user is going (left/right), then decrement/increment the value, and wait for the onResume, or start this activity again with the android:launchMode="singleTask" modifier in that "view book page" Activity
onDestroy() Destroy everything you created to free the memory.
I've got a problem that I'm having problems solving. My app has 2 types of fragments. When the app starts, a fragment with main menu is added to a FrameLayout that I use as a fragment container. This fragment takes up the entire screen. Then, when I choose one of the items in the menu, a corresponding fragment should be loaded into the container, replacing the menu. However, this fragment must only take 1/4 of the screen from the left, and the space outside is to be used by some other fragment.
I was thinking about making 3 FrameLayouts, one for the left side, one for the right and one for the entire screen, but this is going to have problems with fragment transactions, since I would have to keep tabs on which fragments are where and remove them by hand.
Basically what I need is some way to change whether my fragments are loaded into a container that takes up full screen, or a container that takes up only some part of the screen. I probably could do it with tons of trail and error and some code, but I bet there is a really easy way to do this in android that I missed.
Instead of trying to dynamically load these fragments into the various containers, I would suggest having two different Activities.
It sounds like the main menu fragment will only ever appear on its own in full screen. So, make that a full Activity (let's call it MainMenuActivity).
The second activity will have two FrameLayouts as it's contents, with one taking up 1/4 of the screen and the other taking up the remaining 3/4. Load this second activity upon choosing a main menu option and populate the fragments in onCreate() of the second activity.
Hitting the back button from the second activity will return the user to MainMenuActivity.
Could someone please point me to the right direction in terms of managing complex navigation flow in Android application.
The use case is as follows: User may click on a thumbnail in a grid of thumbnails, this takes user to "detailed" view of an image. This detailed view in addition to details of particular image has list/carousel of "related" images to the image. User clicks on one of related and taken to "detailed" view of that image. And so on and so on.
This basically creates a stack of unlimited/unknown length.
By hitting "back" button user is taken to previous view.
The task: I want to be able to set some limit to the views stack. So for example if user has navigated to 10-th "detailed" view - they will have to hit "back" only 3 times to get to grid of thumbnails where they have started the whole flow.
I am using fragments in my application.
Would really appreciate any help.
I'd use 2 activities. One activity shows the grid, the other the detailed view. The detailed view maintains a stack of previous images, with max length 3. When a related image is pressed, you push the current image onto the stack , dropping the oldest if needed. Then redisplay for the new image. Override onBackPressed to pop the image from the stack. If the stack is empty, call finish() and you'll return to the grid.
One suggestion i would say is not Open a new Activity for "detailed" view .Instead just refresh the activity with the new supporting data.This way there would be only 2 activities in your activity stack.In case you would want atleast the last 3 detail pages then override back button and maintain a stack of 3 images to show the details page.
I am very new to android development. I am trying to create a simple two activities based ebbok type application where activity1 is table of content and activity2 displays the details. I have a listview in Activity1 where I list the table of content. On clicking any specific content, I load activity2. In onCreate of activity2, I load the content into a string(from a txt file in assets). and display that in textView (as defined in activity2.xml). So far so good. The challenge now is to display the content page-wise because, as of now all of my string gets loaded into a single page in activity2. So I added two buttons at the bottom of activity2 (defined that in activity2.xml). My planned logic now is
get the screen height (I could get that)
get the botton height and substract 2) from 1). Now I cannot do this becuase I cannot get button height in onCreate of Activity2
and then find how much text I can fit in one page, find number of pages accordingly, use a page index and using a page delimiter, keep loading remaining text into next pages when user clicks "next" button.
So i need help with
-how to get button width as I have mentioned in 2)
-and any sample code you can share to perform 3) above will also help me.
any help here from any one of you experts out there will be much appreciated.
Using Fragements will Solve your problem.
Fragements :
A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).
For example, a news application can use one fragment to show a list of articles on the left and another fragment to display an article on the right—both fragments appear in one activity, side by side, and each fragment has its own set of lifecycle callback methods and handle their own user input events. Thus, instead of using one activity to select an article and another activity to read the article, the user can select an article and read it all within the same activity
For More About fragements just go through this link.
Hope it will help you.
I figured out a much efficient way to display a long string across number of pages. -I display the long text into the text view and disable scrolling -I then find out the lines in the layout and lines on single screen, hence I know how many screens(pages) will the long string span across -Then whenever user clicks a button to go to next page or swipes screen to go to the next page then I use TexView.scrollTo() function to move to number of lines(as many on a screen) forward. So it becomes as good as moving to next page
I'm building this application where I have 2 activities. Both of them consist of 3 fragment - one for title, one for content and one for tab control. It is shown at image below.
First activity serves for showing list of some data's headers (item name etc.), search, app info etc. When user presses item in list, app takes him to another activity to show him detail of chosen item. This "details" activity has 6 different content fragments and user switch between them via buttons in tab control fragment (I did switching between content fragments by showing chosen one and hiding all others - I don't know if it's right way, it's my firs app so it came to my mind at first :) ).
And what I would like to do is: When I'm in detail and I swipe left/right then I want app to take me to previous/next item's detail, to same fragment where I currently was in (so not to next content fragment, but to detail of next item in 1st activity's list).
Is this somehow possible please? Because I have totally no clue how to do it :)
And what I would like to do is: When I'm in detail and I swipe
left/rigt then I want app to take me to previous/next item's detail,
to same fragment where I currently was in (so not to next content
fragment, but to detail of next item in 1st activity's list).
If you want to swipe left-right then you would need a ViewPager widget. I'm not sure how should your details activity behave so I'm providing you with two options. Do you want to be able to switch to the next/previous item's details only when a certain fragment is the one currently viewed by the user(from the 6 content fragments, which I assume are related and show various data for a single item)? If yes then in that desired fragment you would replace the current content of the fragment(which will only act as a container) with a ViewPager and use nested fragments for the actual content. If the user switches to the details of a previous/next item's details and then suddenly wants to see the data for that item from one of the remaining 5 content fragments then you would need to have some updates method on them to refresh the data to show the current item(a OnPageChangeListener will be useful here).
Second option, is if you want to allow the user to swipe left/right from any of the 6 content fragments. If this is the case you would use the same method as above but you'll modify each of those 6 fragments.
Showing the next/previous item is easy, just get some sort of identifier of the data(a position, id), retrieve the whole used data(as in the first activity) and then cycle between it.