Instructions Activity Android Studio - android

I would like to create activity in which it would be explained how the app is supposed to be used. On a click on a button, I would like an Activity to be opened which has next and previous buttons on the bottom. So the first screen after the click on a button would show the first instruction and you can press next to see the next instruction which opens a new screen. After going through all the instructions, I would like a Finish button to return back to the main activity.
My question is can this be made in a single activity or is it actually more activities that differ only by the text and pictures they contain?

Yes it can be done in only one activity(actually 2 if you include the main activity).
What you can do is have multiple TextViews, and when the next button is pressed, you can toggle that 1st instruction's visibility
. And so on for the next instructions. The Next/Previous buttons should determine what Textview is currently visible, so they can keep track what Textview to show next. Use switch statement

Related

Next and previous button implementation in android

I have multiple screens in my app in which each screen has next and previous buttons except the first screen. when I click the previous button on 3rd screen it needs to go back to the 2nd screen and when I click next button on 3rd screen it needs to go to the 4th screen. In addition to it, the data of the screens need to be saved i.e. when I clicked the previous button on 3rd screen then the 2nd screen with already filled should be displayed. Similar with the next button also. Can anyone help me to implement this?
Thank you.

Android app tutorial (text disappearing on back command)

I am following the tutorial here:
http://developer.android.com/training/basics/firstapp/starting-activity.html
When I enter some text into the field and press Send, it goes to the second screen with the larger text, so that part works.
When I click the "back" button on my phone, the text I inputted is still in the text field. But if I press the back button on the screen near the top of the program, the text I inputted is gone.
Why is this and how can I control / change this?
Reason for your issue - Your app creates a new instance of activity when you click the back button in your app.
To fix this
In the back button where you call your first activity, add this line of code
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
What happens with this flag ?
When you use this flag, Android looks for an instance of the desired activity in your activity stack, starting from the front of the stack and scanning until it gets to the root/back of the stack. As soon as it finds an instance of the specified activity, it brings that one to the front (ie: if there are multiple instances of the specified activity it will bring to the front the most recent instance).

Shortcut button on A fragment to perform programmatically an action defined in B without showing it on UI

I have 3 fragments : A, B and C.
A contents a list of element, when you chose an element from the list, it loads B fragment. Inside B, i have a button showPreview, a click on that button loads the C fragment.
I already implemented all of this, and it's working pretty nice.
Now what i want is to add, in A fragment, a shortcut button on each item, to access the preview (C fragment) without showing B fragment on UI like in google play application, you can download an app by clicking on Three dots -> Install, without opening app detail page.
Presently, when user clicks on shortcut button, i load the B fragment first (shown in UI), after i call previewButton.performClick() to click programmatically on the showPreview button. But that's not what i want because i am obliged to show B first, let it load entirely before making a performClick().
I have read about FragmentTransaction methods (attach/detach, add/remove etc.), about fragment lifecycle, etc ... without solution.
So my questions are :
how can i load B fragment without showing it on the UI ?
If that's impossible, how to do the same thing as google play application ?
Finally I resolved the issue. My problem was that I haven't seperate Views from Model. I didn't have to use performClick() anyway, I didn't have to depend on Button click.
I resolved it by just creating a method which does nicely what I want, after I use this method on button click and after shortcut list choice.

options menu does not come up after back button press android

I have an android application where I want to display a LinearLayout when user clicks on options button(I am setting the linear layout's visibility to visible in onCreateOptionsMenu) and make it invisilble when user clicks on back button.
This works fine when I press the option button and then the back button-the view comes up and then goes away respectively.
The problem is when I press the option button again, the linearlayout does not show even though the visibility is being set to visible.
However, log tells me that the methos onCreateOptionsMenu is entered.
Why would this happen?
onCreateOptionsMenu is called only once per activity. In your case you have to code in onPrepareOptionsMenu. This will be called every time the user presses menu key.
Why do you want do this? For android users relevant reaction for menu button is option menu.
What about question, try use View.bringToFront() - it will bring view in front of all views of the same parent.

Refreshing an Activity

I created an Activity which allows navigating between pages with a couple of Buttons (Previous and Next). When the user clicks one of the buttons, the Activity (same) needs to be "refreshed". In order to do this, I set up the buttons to make a call to
onCreate(this);
after they set up the other stuff that the activity uses for the paging to work.
And it is working so far, but I'm wondering if there is a better way. Is there?
You should rethink your approach. Having Previous and Next buttons looks like an iphone's NavigationBar View. Remember that in android you have the back button, so a previous button shouldn't be necessary.
If you wish to do it, check Android's Activity Lifecycle. You should update your Activity on the onStart() method and avoid the call to onCreate(this) which doesn't sound good.
The activity displays data related to a certain day. The navigation allows choosing the day which is being displayed. As such, clicking one of the buttons changes the information which is displayed.
Example:
When the Activity first loads, it shows a given day - let's say August 23rd. Then when the user clicks the activity's "Previous" Button, the Activity shows August 22nd.
Then the user clicks the "Next" button and the Activity shows August 23rd again. If the user clicks the "Next" button again, the Activity will show August 24th.
Doesn't it seam a little strange to only have a "Next" (and rely on the physical "Back" button) ?
Thanks.
I fixed this trough refactoring:
Created a new function with the code that was being executed in onCreate (i.e. Layout initialization, database access and information display). The new function is called by the onCreate method (when the Activity gets the "Create" notification) and at anytime that I need to "refresh" the contents of the Activity (i.e. when a button is pressed).
Thanks for your comments.

Categories

Resources