Below page is the one having data i want to save from user.
How do I make this data to be read on next activity having a editText of text view?
And is this Code correct?
AddMoney.class
public class AddMoney extends AppCompatActivity {
Button b1;
EditText et;
enter code here
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_money);
b1 = (Button) findViewById(R.id.b1);
et = (EditText) findViewById(R.id.et);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
saveData();
AlertDialog.Builder b = new AlertDialog.Builder(AddMoney.this);
b.setIcon(R.mipmap.ic_launcher);
int val = Integer.parseInt(et.getText().toString());
b.setTitle("MONEY ADDED");
String msg = "₹" + val + " has been added in your wallet";
b.setMessage(msg);
b.setCancelable(false);
b.setPositiveButton("OK",null);
AlertDialog d = b.create();
d.show();
}
});
}
public void saveData() {
try {
FileOutputStream fileOutputStream = openFileOutput("Expenses.txt", MODE_PRIVATE);
fileOutputStream.write(et.getText().toString().getBytes());
fileOutputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
As a better approach you can make use of SharedPreference as SripadRaj suggested.
on the first activity,where you save the data:
SharedPreference sp =getSharedPreferences("app_package_name", Context.MODE_PRIVATE);
sp.putString("expense",et.getText().toString());
sp.apply();
On another activity:
SharedPreference sp =getSharedPreferences("app_package_name", Context.MODE_PRIVATE);
String expense = sp.getString("expense","0.0");
Related
public class ActivityEditParent extends AppCompatActivity {
private static final String TAG="ActivityEditParent";
CustomEditText etFirstName,etLastName,etEmail,etPhone;
public static ConnectionDetector detector;
private static final String URL = "http://hooshi.me.bh-in-13.webhostbox.net/index.php/parents/editprofile";
private SharedPreferences sharedPreferences;
private SharedPreferences.Editor editor;
private CustomButton btnSave;
private String parentFirstName,parentLastName,parentPhone;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_parent);
getSupportActionBar().hide();
detector = new ConnectionDetector(ActivityEditParent.this);
getUIComponents();
}
private void getUIComponents(){
etFirstName = (CustomEditText) findViewById(R.id.edit_first_name);
etLastName = (CustomEditText) findViewById(R.id.edit_last_name);
etEmail = (CustomEditText) findViewById(R.id.edit_email_address);
etPhone = (CustomEditText) findViewById(R.id.edit_phone_number);
btnSave = (CustomButton) findViewById(R.id.btn_save_parent);
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
editParent();
}
});
TextView title = (TextView) findViewById(R.id.toolbar_title);
ImageButton back = (ImageButton) findViewById(R.id.toolbar_back);
title.setText("Edit parent");
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
goBack();
}
});
sharedPreferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
editor = sharedPreferences.edit();
String fName = sharedPreferences.getString(AppConstants.PARENT_FNAME,AppConstants.fName);
String lName = sharedPreferences.getString(AppConstants.PARENT_LNAME,AppConstants.lName);
String email = sharedPreferences.getString(AppConstants.PARENT_EMAIL,AppConstants.email);
String phone = sharedPreferences.getString(AppConstants.PARENT_MOBILE,AppConstants.mobile);
etFirstName.setText(fName);
etLastName.setText(lName);
etPhone.setText(phone);
etEmail.setText(email);
}
private void goBack() {
startActivity(new Intent(getApplicationContext(), ActivityEditDetails.class));
finish();
}
private void editParent(){
SharedPreferences preferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = preferences.edit();
JSONObject jsonParam = null;
parentFirstName = etFirstName.getText().toString().trim();
parentLastName = etLastName.getText().toString().trim();
parentPhone = etPhone.getText().toString().trim();
if (detector.checkInternet()){
jsonParam = new JSONObject();
JSONObject header = new JSONObject();
try {
jsonParam.put("parentId",preferences.getString(AppConstants.PARENT_ID,""));
jsonParam.put("parentFN",parentFirstName);
jsonParam.put("parentLN",parentLastName);
jsonParam.put("parentPhone",parentPhone);
jsonParam.put("apiAccessKey",preferences.getString(AppConstants.API_ACCESS_KEY,""));
header.put("parent",jsonParam);
Log.d("POST PARAMETERS:",""+header);
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, URL, header, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.d("Response:",""+response);
String json_status = null;
try {
json_status = response.getString("status");
if (json_status.equalsIgnoreCase("Success")){
Toast.makeText(getApplicationContext(), "changed parent details successfully", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),ActivityHome.class));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
}
});
VolleySingleton.getInstance(getApplicationContext()).addToRequestQueue(jsonObjectRequest);
}
}
}
In the response After getting success message I want save the edited details in in respective edit text fields please help.After success message I am moving to home screen through intent and again I get back to this screen it is showing the previous details only.
all happens here :
...
if (json_status.equalsIgnoreCase("Success")){
Toast.makeText(getApplicationContext(), "changed parent details successfully", Toast.LENGTH_SHORT).show();
startActivity(new Intent(getApplicationContext(),ActivityHome.class));
}
...
once you have a success response save the edited values on the preferences, for example etFirstName, save it is new value to the corresponding preference :
...
if (json_status.equalsIgnoreCase("Success")){
Toast.makeText(getApplicationContext(), "changed parent details successfully", Toast.LENGTH_SHORT).show();
editor.putString(AppConstants.PARENT_FNAME, parentFirstName);
editor.apply(); //don't forget this
startActivity(new Intent(getApplicationContext(),ActivityHome.class));
}
...
any way you're creating the editor but not using it.
you want to save data after download from network or after an edit in edit text fields was made??
if from network add some save method execution statement in code where you download data was successful
if (json_status.equalsIgnoreCase("Success")){
Toast.makeText(getApplicationContext(), "changed parent details successfully", Toast.LENGTH_SHORT).show();
// here you have successful received data so u can map them to edit text or save in shared prefs
// add method to save data here
saveData(response);
startActivity(new Intent(getApplicationContext(),ActivityHome.class));
}
private void saveData(JSONObject response) {
// use JSon response object save here to shared preferences
// see how to load data from json object
// https://processing.org/reference/JSONObject_getString_.html
SharedPreferences sharedPreferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
sharedPreferences.putString(....).apply;
// or set edit text controls with JSon data
}
to save edit text changes you have two choices :
add to layout save button (you have one) button and set on click listener with method to save data:
btnSave = (CustomButton) findViewById(R.id.btn_save_parent);
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
saveData(v);
}
});
private void saveData(View view) {
// get root view
View rootView = view.getRootView();
// find edit text widget on root view
EditText etFirstName = (EditText) rootView.findViewById(R.id.edit_first_name);
// get string from edit text widget
String firstName = etFirstName.getString.toString();
// get shared preferences
SharedPreferences sharedPreferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
// save to shared prefs firstName wher NAME_KEY is string to identified your saved data for later use - to load
sharedPreferences.putString(NAME_KEY,firstName).apply;
}
private void loadDataFromSharedPredferences(View view) {
// get shared preferences
SharedPreferences sharedPreferences = getSharedPreferences(AppConstants.OOSH_PREFERENCES, Context.MODE_PRIVATE);
// load data from shared prefs firstName wher NAME_KEY is string to identified data to load
String firstName = sharedPreferences.getString(NAME_KEY,firstName);
// get root view
View rootView = view.getRootView();
// find edit text widget on root view
EditText etFirstName = (EditText) rootView.findViewById(R.id.edit_first_name);
// set string to edit text widget
etFirstName.setText(firstName);
}
add on text change listener for edittext widgets
ps. you need to clarify - write a exactly steps of what you want to do achieve
load data from network ? then save ?
or save request date ?
or save result data ?
What do you think is wrong with this code ?
I am using this class: https://github.com/btouchard/HttpData/blob/master/README.md
Error:
java.lang.IllegalStateException: Could not execute method of the activity
Location of error: Log.i line!
Thanks for the assistance.
I guess it is a basic solution, but I can't find it.
public class Formulaire extends Activity {
EditText msgTextField;
Button sendButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form);
//make message text field object
msgTextField = (EditText) findViewById(R.id.msgTextField);
//make button object
sendButton = (Button) findViewById(R.id.sendButton);
}
public void send(View v) {
//get message from message box
try {
String MonURL = "http://www.davidmarchioni.fr/glopper/test.txt";
HttpData request = new HttpData(MonURL);
request.header(MonURL);
String html = request.asString();
Thread.sleep(2600);
Log.i("OK >> ", html);
Toast.makeText(getApplicationContext(), html, Toast.LENGTH_SHORT).show();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
well try on catching Exception, what if String html comes null? what maybe the reason
I have 2 activities namely MainActivity and OKActivity. The MainActivity statically checks for a password and lets you go to the OKActivity. I have used SharedPrefrences in the OKActivity for changing the password to a new one.
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText password = (EditText) findViewById(R.id.editText_Password);
Button enter = (Button) findViewById(R.id.button);
enter.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
String user_pass;
user_pass = password.getText().toString();
if (user_pass.isEmpty()) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
dialogBuilder.setIcon(R.drawable.ic_launcher);
dialogBuilder.setTitle("Oops!");
dialogBuilder.setMessage("Password Field Cannot Be Empty");
dialogBuilder.setPositiveButton("OK", null);
dialogBuilder.show();
}
else
if (user_pass.equals("123")) {
Toast.makeText(MainActivity.this, "Welcome!", Toast.LENGTH_SHORT).show();
Intent I = new Intent("com.mavenmaverick.password.OKActivity");
startActivity(I);
}
else
if(user_pass != ("123")){
Toast.makeText(MainActivity.this, "Incorrect", Toast.LENGTH_SHORT).show();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MainActivity.this);
dialogBuilder.setIcon(R.drawable.ic_launcher);
dialogBuilder.setTitle("Oops!");
dialogBuilder.setMessage("Incorrect Password");
dialogBuilder.setPositiveButton("OK", null);
dialogBuilder.show();
}
}
});
}
public class OKActivity extends Activity {
EditText newPassword;
String newUserPassword;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ok);
newPassword = (EditText) findViewById(R.id.new_password);
newUserPassword = newPassword.getText().toString();
getpasswordSharedPreferences();
Button changePassword = (Button) findViewById(R.id.button_change);
changePassword.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
newUserPassword = newPassword.getText().toString();
getpasswordSharedPreferences();
setSharedPreferences();
}
});
}
private String getpasswordSharedPreferences() {
SharedPreferences userPassword = getSharedPreferences("USER_PASSWORD", MODE_PRIVATE);
String password = userPassword.getString("THE_PASSWORD", "123");
return password;
}
private void setSharedPreferences() {
SharedPreferences userPassword = getSharedPreferences("USER_PASSWORD", MODE_PRIVATE);
SharedPreferences.Editor password_edior = userPassword.edit();
password_edior.putString("THE_PASSWORD", newUserPassword);
password_edior.commit();
Toast.makeText(OKActivity.this, "Password Change Succesful", Toast.LENGTH_SHORT).show();
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(OKActivity.this);
dialogBuilder.setIcon(R.drawable.ic_launcher);
dialogBuilder.setTitle("Done!");
dialogBuilder.setMessage("New Password : "+newUserPassword);
dialogBuilder.setPositiveButton("OK", null);
dialogBuilder.show();
}
How can I access the SharedPrefrences in OKActivity for the password and use it in my MainActivity to allow access thereby making things dynamic over user-interaction cycles.
Just access the SharedPreferences in your OKActivity and in your MainActivity. The trick is to use the same TAG name - in your case it's 'USER_PASSWORD'.
Have a look at this --> SharedPreferences
Create a SharedPrefrences.java //then we can use when ever we need
public class SharedPrefrences {
public static void saveData(String name, String value, Context context) {
try {
SharedPreferences settings = context
.getSharedPreferences(Configuration.getPrefsName(), 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString(name, value);
editor.commit();
} catch (NullPointerException ignored) {
}
}
public static String getData(String name, Context context) {
try {
SharedPreferences settings = context
.getSharedPreferences(Configuration.getPrefsName(), 0);
return settings.getString(name, "");
} catch (NullPointerException ignored) {
return "";
}
}
}
//In MainActivity
SharedPrefrences.saveData("Password","123456", getApplicationContext());
//In OKActivity
String passwordfromMainActivty = PreferencesUtils.getData("Password", getApplicationContext());
//To Add Newpassword
SharedPrefrences.saveData("NewPassword","abcd", getApplicationContext());
You get the same way in both activity's. Do get of your SharedPreferences with the same TAG.
private String getpasswordSharedPreferences() {
SharedPreferences userPassword = getSharedPreferences("USER_PASSWORD", MODE_PRIVATE);
String password = userPassword.getString("THE_PASSWORD", "123");
return password;
}
Maybe you can put this method's in other class, and call when you want from all activities:
You can put your set method here too
For example:
public class SharedPrefs {
private static final String SHARED_PREF = "USER_PASSWORD";
private static final String KEY_PASSWORD = "THE_PASSWORD";
public static void getStoredSharedPref(Context context, String key, String value) {
SharedPreferences sharedPref = context.getSharedPreferences(SHARED_PREF, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(propertyKey, value);
editor.commit();
}
}
and then call in your activities
SharedPrefs.getStoredSharedPref(context, SharedPrefsUtils.KEY_PASSWORD,"1234");
I am making an app that takes two strings through edittext. I want to store these strings in Internal Storage but I am getting error: "java.io.FILENOTFOUNDEXCEPTION".
public class MyActivity extends Activity {
public Button save;
public EditText user;
public EditText pass;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
user = (EditText) findViewById(R.id.username);
pass = (EditText) findViewById(R.id.password);
save = (Button) findViewById(R.id.button);
save.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String un = (String) user.getText().toString();
String pw = (String) pass.getText().toString();
//Creating file for saving username and passwords
String PRONTO = "PrivateData";
FileOutputStream fos = openFileOutput(PRONTO, Context.MODE_PRIVATE);
fos.write(un.getBytes());
fos.close();
}
});
}
}
Replace
FileOutputStream fos = openFileOutput(PRONTO, Context.MODE_PRIVATE);
with
FileOutputStream fos;
try {
fos = openFileOutput(PRONTO, Context.MODE_PRIVATE);
fos.write(un.getBytes());
fos.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
I have two activities:
1.Main Activity which contains listview;
2.Second Activity which add item to listview in Main Activity.
For Second Activity I created layout-land layout for landscape.
After Second Activity is opens in portrait, I change it to landscape mode - Second Activity close and app return to Main Activity.
Questions:
1.How save entered to EditText fields values after orientation is changed?
2.And how to apply layout-land to Second Activity when change screen orientation to landscape?
UPD
Second activity code:
public class AddItem extends MainScreen implements OnClickListener{
final String LOG_TAG = "myLogs";
EditText comment_enter, link_enter, password_enter, login_enter, title_enter, date_enter;
Button add_item_button, add_more_button, clear_close_button;
CheckBox showPass;
DBHelper db;
DataBase DB;
SimpleCursorAdapter passListViewAdapter;
SimpleDateFormat sdf;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_item);
Log.d(LOG_TAG, "before edit : ");
comment_enter = (EditText) findViewById(R.id.comment_enter);
link_enter = (EditText) findViewById(R.id.link_enter);
password_enter = (EditText) findViewById(R.id.password_enter);
login_enter = (EditText) findViewById(R.id.login_enter);
title_enter = (EditText) findViewById(R.id.title_enter);
date_enter = (EditText) findViewById(R.id.date_enter);
showPass = (CheckBox) findViewById(R.id.showPass);
showPass.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
Log.d(LOG_TAG, "is checked : " + isChecked);
if (isChecked) {
password_enter.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
}
else {
password_enter.setInputType(129);
}
}
});
add_item_button = (Button) findViewById(R.id.add_item_button);
add_item_button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d(LOG_TAG, "add_item_button : ");
String title_str = title_enter.getText().toString();
String login_str = login_enter.getText().toString();
String pass_str = password_enter.getText().toString();
String link_str = link_enter.getText().toString();
String comm_str = comment_enter.getText().toString();
String date_str = date_enter.getText().toString();
byte[] login_byted = null;
try {
login_byted = login_str.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String login_crypted = Base64.encodeToString(login_byted, Base64.DEFAULT);
Log.d(LOG_TAG, "Crypted login" + login_crypted);
byte[] pass_byted = null;
try {
pass_byted = pass_str.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String pass_crypted = Base64.encodeToString(pass_byted, Base64.DEFAULT);
Log.d(LOG_TAG, "Crypted login" + pass_crypted);
DataBase DB = new DataBase(AddItem.this);
DB.open();
DB.insertPass(title_str, login_crypted, pass_crypted, link_str, comm_str, date_str);
DB.close();
Log.d(LOG_TAG, "after inserting into DB : ");
finish();
}
});
add_more_button = (Button) findViewById(R.id.add_more_button);
add_more_button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d(LOG_TAG, "add_more_button : ");
String title_str = title_enter.getText().toString();
String login_str = login_enter.getText().toString();
String pass_str = password_enter.getText().toString();
String link_str = link_enter.getText().toString();
String comm_str = comment_enter.getText().toString();
String date_str = date_enter.getText().toString();
byte[] login_byted = null;
try {
login_byted = login_str.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String login_crypted = Base64.encodeToString(login_byted, Base64.DEFAULT);
Log.d(LOG_TAG, "Crypted login" + login_crypted);
byte[] pass_byted = null;
try {
pass_byted = pass_str.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String pass_crypted = Base64.encodeToString(pass_byted, Base64.DEFAULT);
Log.d(LOG_TAG, "Crypted login" + pass_crypted);
DataBase DB = new DataBase(AddItem.this);
DB.open();
DB.insertPass(title_str, login_crypted, pass_crypted, link_str, comm_str, date_str);
DB.close();
Log.d(LOG_TAG, "after inserting into DB : ");
fieldClear();
String link_enter_str = link_enter.getText().toString();
if(link_enter_str.equals("")){
link_enter.setText("http://www.");
}
}
});
clear_close_button = (Button) findViewById(R.id.clear_close_button);
clear_close_button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Log.d(LOG_TAG, "clear/close click button : ");
boolean checkRes = emptyAllCheck();
Log.d(LOG_TAG, "result : " + checkRes);
if(checkRes == true){
finish();
}
fieldClear();
}
});
if(savedInstanceState != null){
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Log.d(LOG_TAG, "title : " + savedInstanceState.getString("title"));
title_enter.setText(savedInstanceState.getString("title"));
login_enter.setText(savedInstanceState.getString("login"));
password_enter.setText(savedInstanceState.getString("pass"));
link_enter.setText(savedInstanceState.getString("link"));
comment_enter.setText(savedInstanceState.getString("comm"));
date_enter.setText(savedInstanceState.getString("date"));
add_item_button = (Button) findViewById(R.id.add_item_button);
add_more_button = (Button) findViewById(R.id.add_more_button);
}
else {
Log.d(LOG_TAG, "before getting date : ");
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
String date = sdf.format(new Date(System.currentTimeMillis()));
date_enter.setText(date);
}
}
#Override
protected void onPause() {
super.onPause();
finish();
Log.d(LOG_TAG, "onPause : ");
}
#Override
protected void onResume(){
super.onResume();
}
protected void onSaveInstanceState(Bundle saveInstance) {
super.onSaveInstanceState(saveInstance);
String title_str = title_enter.getText().toString();
String login_str = login_enter.getText().toString();
String pass_str = password_enter.getText().toString();
String link_str = link_enter.getText().toString();
String comm_str = comment_enter.getText().toString();
String date_str = date_enter.getText().toString();
saveInstance.putString("title", title_str);
saveInstance.putString("login", login_str);
saveInstance.putString("pass", pass_str);
saveInstance.putString("link", link_str);
saveInstance.putString("comm", comm_str);
saveInstance.putString("date", date_str);
Log.d(LOG_TAG, "onSaveInstanceState +" + title_str + login_str + pass_str + link_str + comm_str + date_str);
}
public void fieldClear(){
comment_enter.setText("");
link_enter.setText("http://www.");
password_enter.setText("");
login_enter.setText("");
title_enter.setText("");
}
public boolean emptyAllCheck(){
String title_str = title_enter.getText().toString();
String login_str = login_enter.getText().toString();
String pass_str = password_enter.getText().toString();
String link_str = link_enter.getText().toString();
String comm_str = comment_enter.getText().toString();
if (title_str.equals("") && login_str.equals("") && pass_str.equals("") && link_str.equals("http://www.") && comm_str.equals("")) {
return true;
}
return false;
}
}
i advise you to read a bit more about Android Activity life cycle it will help you.
However on configuration Change android destroy you are activity and recreate and you can use the callback method OnsavedInstanceState() to save you instance (it will be call automatically by the system on configuration change)
example
public void onSaveInstanceState(Bundle savedInstanceState){
super.onSaveInstanceState(savedInstanceState);{
String savedText = myEditText.getText().toString();
savedInstanceState.putString("Key", savedText);
}
Now when the app is recreated on OnCreate method retrieve your saved text as follow :
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(savedInstanceState != null){
myEditText.setText(savedInstanceState.getString("Key");
//the rest of the code}
Voila and I hope that is that you meant.
use this one:
android:configChanges="orientation|screenSize"
add this code in your manifest file. No need to save the edit text variable.