Android's mechanism to save/restore activity state - android

For my first Android app I have (hopefully) followed the tutorial at developer.android.com to the letter. The finished app has an EditText view where you can enter text and a SEND button which will open a new activity (DisplayMessageActivity) which displays the text in the EditText in large font.
I have noticed some inconsistent behaviour regarding the persistence of the text in the EditText. Assume I have entered some text there:
When I hit the Back button at the bottom of my phone and restart the app from the icon I loose the text.
When I hit the Home buttom at the bottom of my phone and restart the app from the icon I keep the text.
When I press the SEND button and leave the DisplayMessageActivity via the Back button at the bottom of my phone I keep the text.
When I press the SEND button and leave the DisplayMessageActivity via the arrow button in the action bar I loose the text.
Can anyone explain to me why the behaviour is different and what I have to do to retain the text in all four cases?

Related

How to tap a button with one touch, when keyboard is open (instead of 2)

I have the keyboard open in my app, I want the user to be able to type, and then tap a colour selector widget I have made (which changes text colour). The problem is that it takes 2 taps, the first one closes the keyboard, the second one actually selects my colour picker. Is there a way to make this one tap? and also keep the keyboard open if possible, so they can change colour then go back to typing without focus issues.

Application blacks out and stops responding when returning back from another app

I am developing this app that contains a webview and also an actionbutton on its Toolbar that would allow the user to send a text message to the a number. Thing is im using an implicit intent and Intent.Action_View to be able to send a text message using default text message tool. The problem is when i press back button either from the toolbar or device button it goes back and does not show anything except a Black screen (fully black screen) and stops responding. Its a strange behaviour. Please let me know what to do about it. Thanks in advance.

Android IME back button is hide my keyboard and EditText of Twitter app

I've made a custom soft keyboard extended from InputMethodService class, when the user clicks on any EditText, my keyboard will be shown and fill the whole screen (portrait or landscape).
Once I open Twitter application to write a tweet, writing Tweet screen shows up and my keyboard will be shown with no problems.
Once I click back button to hide the keyboard and back to write tweet screen, the keyboard and tweet screen have gone as well! So, any text I've written using my keyboard will be also gone.
I'm not sure if this is Twitter app problem, but I'm not sure how can I solve that? Even if I could handle back button event, what should I do next?
If you also using any soft keyboard, once you click back button, it will hide the keyboard and write a tweet screen as well.
I made a small trick for that, write a text and remove it to get the focus when onWindowShown is called:
getCurrentInputConnection().commitText(" ", 1);
getCurrentInputConnection().deleteSurroundingText(1, 0);
Now everything is working fine :)

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).

How to prevent Button press from closing soft keyboard

I have implemented a note-taking UI where a WebView accepts user input and below it is a row of buttons that toggle formatting inside of the WebView. The buttons sit on the bottom of the layout, so when the soft-keyboard pops up when the WebView has focus the buttons sit just above the keyboard.
This is working great, but my problem is that whenever one of the buttons is pressed the soft-keyboard closes. I want to leave the soft-keyboard as it is whenever a button is pressed. So if it is closed, a button press won't open it, and if it is open then a button press won't close it.
I found the Wordpress Android source code, and the layout is extremely similar and it has the exact button-keyboard interaction I want.
The relevant sources on GitHub are here Activity Code and here Layout XML
I can't figure out how they do it though. They don't call the InputMethodManager, which I am trying to avoid if possible since it can cause jumpy behavior where the keyboard has to re-open itself whenever a button is pressed. The one similar question I found had answers that essentially said to do exactly that, or create a useless view to get the focus to prevent the keyboard from closing. Neither seem very efficient.

Categories

Resources