I'm trying to restart an Activity in my App, but I have some problems.
When I use recreate();
, the activity doesn't completely restart, the EditTexts don't get empty.
I also tried this code:
Intent myIntent = getIntent();
myIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
startActivity(myIntent);
BUT:
At the start, my Activity have an EditText and it get auto-focus. I'm using this code to open Keyboard when focus, and close when lost focus:
txtNumber.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (hasFocus) {
imm.showSoftInput(txtNumber, InputMethodManager.SHOW_IMPLICIT);
} else {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
});
But it doesn't works when Activity starts, so i had to add android:windowSoftInputMode="stateVisible"
to the AndroidManifest.xml.
The problem is that: the 2nd code (for restart the activity) ignore this, and don't open the Keyboard at the start.
How can I open the Keyboard at the Activity Start programmatically? Or how can I completely restart an activity using recreate();
?
Sorry for bad english, I hope you understand.