What means this button state when my activity starts? - android

When my activity starts the button starts as below image, seems that it is selected.
button seems to be selected http://kodeinfo.com/wp-content/uploads/2014/03/post4_1.jpg
Button seems to be selected but I don't select it neither on activity nor layout.
I had checked and this is not related to focus. I tried starting the activity with requestFocus() on a button and does not have the same behavior.
Does anyone knows what is that? What is this state for the button? I don't want this behavior in my app, but I'm not being able to understand the issue in my code because I don't know what this state is.

Related

How do I update Spinners in a MainActivity when clicking either the ToolBar back arrow or phone Back button?

Problem:
How would I refresh Spinner data in a MainActivity through the use of the ToolBar back arrow or phone "back button?"
What I am trying to do (would like to do):
Right now, clicking the toolbar back arrow or back button just takes me back to the MainActiity previous state... which is expected behavior without any activity updates. What I wanted to do was trigger some updates to the Spinners in the MainActivity.
How the app spinners function (High-Level):
In my MainActivity are two Spinners called Topic and Question used to return results on the choices made and the user clicks on the results returned to take them to other activities. In later activities, the list data used in the spinners may have been updated or changed. For example, a Topic may have been added or removed. So, when the user eventually returns to the MainActivity, I would like for that list to be updated.
What I have done:
My thought was I would need to use the toolbar arrow or phone back button OnClick with an Intent. Truthfully, both the arrow and button have to function the same in this respect. Unless someone thought there was a better solution, which I'm open to, this was my solution for updating the spinners in the main activity. I was struggling to find how this may be done with the ToolBar arrow and the Back Button.... and whether that was the right solution. I would like to avoid creating a menu button to do the same if I can use the arrow and back buttons.
Below are 3 images demonstrating how this works. Image 1, the user chose a Question to return a result. Image 2 is the result with the Question edited. In image 3, the Main Activity spinner retains the old list and value and there is no result because the question was changed and there is nothing to return for this question value now.
Question choice and result
Question was edited by user
Old question list value remains - there's no result due to the change

How to keep the state of keyboard same of previous activity?

In my activity I have a list of images and one EditText. When I click the image, I use intent to display image in fullscreen activity. when I press the back button the keyboard does not in the same state. I mean when hide the keyboard it displays on its own. Please help me how to maintain the state of keyboard. Thanks in advance.
Put focus on edit text again when activity resumes again after back press in full screen image view.
save the state of keyboard on a class field boolean. than onresume of the previous actvity you set the keyboard to shown or hidden depending on the saved value.

Back button takes 3 attempts

I'm developing an android app, and not understanding the back button.
There is an Activity (say A1) from which by clicking a button, user goes to another Activity (say A2). Once the user has finished with A2 activity, he clicks back-button, to go back to previous activity A1. All the docs say, A1 will onResume() at this point.
And it does. However, if I am in A2, and change the screen orientation (from landscape to portrait or vice versa), then something very different happens. The A2 activity lays itself out again, into the different screen orientation as expected. When I press BACK now, the Activity A2 lays itself out again (no change to screen orientation). Pressing BACK again, again causes Activity A2 to lay itself out again. A THIRD press on back takes you back to Activity A1.
What am I doing wrong here, what am I missing? Thanks
Peter
My question was not phrased completely correctly. I slightly simplified the case. I am using a Spinner, not a Button, to transfer to the next Activity.
Spinner (and Gallery) have a gross bug, not mentioned in the docs - the OnItemSelectedListener event handler is called when a user physically clicks the spinner control, and also when a spinner is first laid out by the framework code. Your spinner handling code must therefore determine if an event was triggered by a user selection or by the spinner being laid out. The easiest way to do this is to make the first item in a Spinner always be "no selection made yet", and to ignore all events on that selection.
See Android Spinner selection and similar posts.
In my case, the orientation change caused the spinner to get laid out again, and I thus got two events from it, the first the layout event, the second from the previously selected entry. And that caused a bogus second activity to be started, and that meant that 3 presses of the back button were needed to "get back" to the first Activity. It was actually going back on the first press, then the spinner fired a layout event and a regular event putting me in the second Activity twice. That wasn't seen on the screen, but was seen using log messages.
When you change orientation, the current Activity is destroyed, and a new Activity created/started.
When you change orientation and press the back key, the previous Activity is popped from the top of the paused stack, destroyed, and a new version of that Activity created/started.
When you change screen orientations, the Activity in the old orientation is never kept. It will be destroyed immediately, or if it is lower down the Paused stack, it will be destroyed when it comes to the top.
you're not handling configuration changes. Check out this link it may help you.
When you change your orientation from portrait to landscape or landscape to portrait and if you are not handling configuration changes, then the activity is recreated.

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