Home > Tricks & Tips > Lose EditText content when rotating

Lose EditText content when rotating

One common problem as I’ve seen much is that, the `EditText` loses its content while rotating the phone.

Technically, it doesn’t lose it content, because a new `EditText` or a new `Activity` is created everytime you try to rotate the phone if your application doesn’t handle the orientation change.

Ok, if you don’t know about this, please refer to one of my old article discussing about the orientation problems.

For current situation, this is the solution to keep the text on `EditText`:

public static final String SAVED_TEXT_KEY = "SavedText";

protected void onCreate( Bundle savedInstanceState ) {
		// back to normal
        super.onCreate( savedInstanceState );
        setContentView( R.layout.main );

		// ok we back, load the saved text
        if ( savedInstanceState != null ) {
            String savedText = savedInstanceState.getString( SAVED_TEXT_KEY );
            edtMyText.setText( savedText );

public void onSaveInstanceState( Bundle savedInstanceState ) {
	// now, save the text if something overlaps this Activity
    savedInstanceState.putString( SAVED_TEXT_KEY, edtMyText.getText().toString() );


Pete Houston

Categories: Tricks & Tips Tags: , , ,
  1. Syed Abdul Wahab
    December 4, 2011 at 1:12 am

    Can you tell me how to apply sad and smile effects on image using android……….

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: