title: Can't save in SharedPreferences values instead I get : D/InputMethodManager: showSoftInput fail
body: <p>I am stuck for a few hours and can't find a solution (at least not for my level) that works, so I am asking for your help. Again.
  I am trying to save some values given by a user from EditText boxes to SharedPreferences. For some reason, instead of : 1, 5 or whatever value I input, I receive this values :</p>
  <p><code>view:androidx.appcompat.widget.AppCompatEditText{b869139 VFED..CL. .F....ID 52,0-247,136 #7f0800a1 app:id/etTigPeZi}</code></p>
  <p>The same java code is used in other app and works just fine. For some reason here doesn't.
  I tryied to search for any mistakes I could have made but, well, I didn't find any.
  Please have a look and if you can SAVE ME !<br />
  Thank you.
  Wish you all a Happy New Year, btw.
  Best regards,
  R.P.</p>
  <p>In Logcat, Verbose :</p>
  <pre><code>2020-12-31 00:46:31.030 28160-28160/ro.pfeilmayer.since_stoppedsmoking D/InputMethodManager: showSoftInput fail, mServedView:DecorView@d9c9e35[Settings] view:androidx.appcompat.widget.AppCompatEditText{b869139 VFED..CL. .F....ID 52,0-247,136 #7f0800a1 app:id/etTigPeZi}
  2020-12-31 00:46:31.040 28160-28160/ro.pfeilmayer.since_stoppedsmoking D/InputMethodManager: showSoftInput fail, mServedView:DecorView@d9c9e35[Settings] view:androidx.appcompat.widget.AppCompatEditText{97bf0df VFED..CL. .F....ID 82,160-217,296 #7f0800a0 app:id/etTigInPachet}
  2020-12-31 00:46:31.060 28160-28160/ro.pfeilmayer.since_stoppedsmoking D/InputMethodManager: showSoftInput fail, mServedView:DecorView@d9c9e35[Settings] view:androidx.appcompat.widget.AppCompatEditText{8a3b12c VFED..CL. .F....ID 0,320-300,456 #7f08009f app:id/etCostPer 
  </code></pre>
  <p>My XML :</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:background=&quot;@drawable/gradient_orange_red&quot;
      tools:context=&quot;.Settings&quot;&gt;
  
  
      &lt;LinearLayout
          android:id=&quot;@+id/linearLayout3&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:background=&quot;#fff&quot;
          android:gravity=&quot;center&quot;
          android:orientation=&quot;vertical&quot;
          app:layout_constraintBottom_toTopOf=&quot;@+id/imageView5&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toBottomOf=&quot;@+id/linearLayout4&quot;&gt;
  
          &lt;TextView
              android:id=&quot;@+id/showTheDateSetted&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginTop=&quot;16dp&quot;
              android:gravity=&quot;center&quot;
              android:hint=&quot;the day you quit&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
          &lt;Button
              android:id=&quot;@+id/buttonSetTheDate&quot;
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginTop=&quot;8dp&quot;
              android:text=&quot;change&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/showTheDateSetted&quot; /&gt;
  
  
          &lt;androidx.constraintlayout.widget.ConstraintLayout
              android:layout_width=&quot;wrap_content&quot;
              android:layout_height=&quot;wrap_content&quot;
              android:layout_marginTop=&quot;32dp&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toBottomOf=&quot;@+id/buttonSetTheDate&quot;&gt;
  
              &lt;LinearLayout
                  android:id=&quot;@+id/linearLayout2&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:gravity=&quot;center&quot;
                  android:orientation=&quot;horizontal&quot;
                  app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
  
                  &lt;LinearLayout
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginRight=&quot;4dp&quot;
                      android:layout_weight=&quot;2&quot;
                      android:gravity=&quot;end&quot;
                      android:orientation=&quot;vertical&quot;&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/tvTigPeZi&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
  
                          android:layout_marginBottom=&quot;32dp&quot;
                          android:text=&quot;Smoked daily : &quot; /&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/tvTigInPachet&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
  
                          android:layout_marginBottom=&quot;32dp&quot;
                          android:text=&quot;Cigarettes/Pack : &quot; /&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/tvCostPerPachet&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
  
                          android:text=&quot;Cost/Pack : &quot; /&gt;
  
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:id=&quot;@+id/ValLayoutReset&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_weight=&quot;1&quot;
                      android:gravity=&quot;center&quot;
                      android:orientation=&quot;vertical&quot;&gt;
  
                      &lt;EditText
                          android:id=&quot;@+id/etTigPeZi&quot;
                          android:layout_width=&quot;65dp&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:ems=&quot;1&quot;
                          android:gravity=&quot;center&quot;
                          android:hint=&quot;12&quot;
                          android:inputType=&quot;number&quot;
                          android:selectAllOnFocus=&quot;true&quot;
                          android:textCursorDrawable=&quot;@null&quot; /&gt;
  
                      &lt;EditText
                          android:id=&quot;@+id/etTigInPachet&quot;
                          android:layout_width=&quot;45dp&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:layout_marginTop=&quot;8dp&quot;
                          android:layout_marginBottom=&quot;8dp&quot;
                          android:ems=&quot;1&quot;
                          android:gravity=&quot;center&quot;
                          android:hint=&quot;20&quot;
                          android:inputType=&quot;number&quot;
                          android:selectAllOnFocus=&quot;true&quot;
                          android:textCursorDrawable=&quot;@null&quot;
                          app:layout_constraintBottom_toTopOf=&quot;@+id/editTextNumberDecimal2&quot;
                          app:layout_constraintTop_toBottomOf=&quot;@+id/editTextNumber&quot;
                          app:layout_constraintVertical_bias=&quot;0.0&quot;
                          /&gt;
  
                      &lt;EditText
                          android:id=&quot;@+id/etCostPerPachet&quot;
                          android:layout_width=&quot;100dp&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:ems=&quot;1&quot;
                          android:gravity=&quot;center&quot;
                          android:hint=&quot;7.58&quot;
                          android:inputType=&quot;numberDecimal&quot;
                          android:selectAllOnFocus=&quot;true&quot;
                          android:textCursorDrawable=&quot;@null&quot; /&gt;
                  &lt;/LinearLayout&gt;
  
                  &lt;LinearLayout
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginLeft=&quot;10dp&quot;
                      android:layout_weight=&quot;1&quot;
                      android:orientation=&quot;vertical&quot;&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/tvTigPeZiSuffix&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:layout_marginEnd=&quot;16dp&quot;
                          android:layout_marginBottom=&quot;32dp&quot;
                          android:text=&quot; cigarettes&quot; /&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/tvTigInPachetSuffix&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:layout_marginEnd=&quot;16dp&quot;
                          android:layout_marginBottom=&quot;32dp&quot;
                          android:text=&quot; pcs&quot; /&gt;
  
                      &lt;TextView
                          android:id=&quot;@+id/tvCostPerPachetSuffix&quot;
                          android:layout_width=&quot;wrap_content&quot;
                          android:layout_height=&quot;wrap_content&quot;
                          android:layout_marginEnd=&quot;16dp&quot;
                          android:text=&quot; currency&quot; /&gt;
  
                  &lt;/LinearLayout&gt;
  
              &lt;/LinearLayout&gt;
  
              &lt;Button
                  android:id=&quot;@+id/buttonSaveAll&quot;
                  android:layout_width=&quot;wrap_content&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;4dp&quot;
                  android:text=&quot;Apply&quot;
                  app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
                  app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                  app:layout_constraintStart_toStartOf=&quot;parent&quot;
                  app:layout_constraintTop_toBottomOf=&quot;@+id/linearLayout2&quot; /&gt;
          &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
      &lt;/LinearLayout&gt;
  
      &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id=&quot;@+id/floatingABBack&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginEnd=&quot;16dp&quot;
          android:layout_marginBottom=&quot;16dp&quot;
          android:clickable=&quot;true&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintHorizontal_bias=&quot;1.0&quot;
          app:layout_constraintStart_toEndOf=&quot;@+id/imageView5&quot;
          app:srcCompat=&quot;@drawable/abc_vector_test&quot; /&gt;
  
      &lt;LinearLayout
          android:id=&quot;@+id/linearLayout4&quot;
          android:layout_width=&quot;411dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:background=&quot;#fff&quot;
          android:gravity=&quot;center&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;&gt;
  
          &lt;ImageView
              android:id=&quot;@+id/imageView4&quot;
              android:layout_width=&quot;125dp&quot;
              android:layout_height=&quot;125dp&quot;
              android:layout_marginTop=&quot;8dp&quot;
              android:layout_marginBottom=&quot;10dp&quot;
              app:layout_constraintBottom_toTopOf=&quot;@+id/linearLayout3&quot;
              app:layout_constraintEnd_toEndOf=&quot;parent&quot;
              app:layout_constraintHorizontal_bias=&quot;0.498&quot;
              app:layout_constraintStart_toStartOf=&quot;parent&quot;
              app:layout_constraintTop_toTopOf=&quot;parent&quot;
              app:layout_constraintVertical_bias=&quot;0.186&quot;
              app:srcCompat=&quot;@drawable/sicestoppedsmokig512x512&quot; /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;ImageView
          android:id=&quot;@+id/imageView5&quot;
          android:layout_width=&quot;150dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginBottom=&quot;16dp&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:srcCompat=&quot;@drawable/newbottom_devlogo_bk&quot; /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt; 
  </code></pre>
  <p>My java :</p>
  <pre><code>import androidx.appcompat.app.AppCompatActivity;
  import android.app.AlertDialog;
  import android.app.DatePickerDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.Intent;
  import android.content.SharedPreferences;
  import android.os.Bundle;
  import android.text.format.DateFormat;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.inputmethod.InputMethodManager;
  import android.widget.Button;
  import android.widget.DatePicker;
  import android.widget.EditText;
  import android.widget.TextView;
  import android.widget.Toast;
  import com.google.android.material.floatingactionbutton.FloatingActionButton;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.concurrent.TimeUnit;
  
  
  public class Settings extends AppCompatActivity {
  
      SharedPreferences preferences;
      float x1, x2, y1, y2;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_settings);
  
          preferences = getSharedPreferences(&quot;settings_values&quot;, MODE_PRIVATE);
          SharedPreferences settings = getSharedPreferences(&quot;settings_values&quot;, 0);
  
          TextView showDateResult = findViewById(R.id.showTheDateSetted);
  
          if (settings.getString(&quot;Date&quot;, null) == null) {
              handleDateButton();
          } else {
  
              String quitDateMem = preferences.getString(&quot;Date&quot;, &quot;&quot;);
  
              showDateResult.setText(&quot;You quit smoking on : &quot; + quitDateMem);
  
          }
  
          Button mButton = findViewById(R.id.buttonSetTheDate);
  
          //Hide Title Bar !
          getSupportActionBar().hide();
  
          mButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  handleDateButton();
              }
          });
  
          FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.floatingABBack);
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  finish();
              }
          });
  
          //Verificam data exista serati utilizator legat de fumat, daca nu, punem default
          //Luam din memorie setarile fumatorului si le afisam in textview
  
          String savedTigPeZi = preferences.getString(&quot;TigariZilnice&quot;, null);
          EditText tvEdTigPeZi = findViewById(R.id.etTigPeZi);
          tvEdTigPeZi.setText(savedTigPeZi);
  
          String savedTigPePachet = preferences.getString(&quot;TigariPerPachet&quot;, null);
          EditText tvEdTigPePachet = findViewById(R.id.etTigInPachet);
          tvEdTigPePachet.setText(savedTigPePachet);
  
          String savedCostPachet = preferences.getString(&quot;CostPachet&quot;, null);
          EditText tvEdCostPachet = findViewById(R.id.etCostPerPachet);
          tvEdCostPachet.setText(savedCostPachet);
  
  
          //Setari tigari pe zi, cost per pachet, continut pachet si definit campuri
          //Salvare date introduce in campurile de mai sus
  
          findViewById(R.id.buttonSaveAll)
                  .setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                          AlertDialog.Builder builder = new AlertDialog.Builder(Settings.this);
  
                          builder.setTitle(&quot;Save settings&quot;);
                          builder.setMessage(&quot;Are you sure ?&quot;);
  
                          builder.setPositiveButton(&quot;Yes&quot;, new DialogInterface.OnClickListener() {
                              public void onClick(DialogInterface dialog, int which) {
                                  // Do nothing but close the dialog
  
                                  EditText etTigariPeZi = findViewById(R.id.etTigPeZi);
                                  if (etTigariPeZi.getText().toString().length() == 0)
                                      etTigariPeZi.setError(&quot;Valid number is required !&quot;);
                                  else {
                                      String stringTigariPeZi = etTigariPeZi.toString();
                                      SharedPreferences.Editor editorPezi = settings.edit();
                                      editorPezi.putString(&quot;TigariZilnice&quot;, stringTigariPeZi);
                                      editorPezi.apply();
                                      String saveTigariZilnice = preferences.getString(&quot;TigariZilnice&quot;, null);
                                      etTigariPeZi.setText(saveTigariZilnice);
                                      etTigariPeZi.requestFocus();
                                      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                      imm.showSoftInput(etTigariPeZi, InputMethodManager.SHOW_IMPLICIT);
                                      imm.hideSoftInputFromWindow(etTigariPeZi.getWindowToken(), 0);
                                  }
  
                                  EditText etTigariIntrunPachet = findViewById(R.id.etTigInPachet);
                                  if (etTigariIntrunPachet.getText().toString().length() == 0)
                                      etTigariIntrunPachet.setError(&quot;Valid number is required !&quot;);
                                  else {
                                      String stringTigariIntrunPachet = etTigariIntrunPachet.toString();
                                      SharedPreferences.Editor editorInPachet = settings.edit();
                                      editorInPachet.putString(&quot;TigariPerPachet&quot;, stringTigariIntrunPachet);
                                      editorInPachet.apply();
                                      String saveTigariPerPachet = preferences.getString(&quot;TigariPerPachet&quot;, null);
                                      etTigariIntrunPachet.setText(saveTigariPerPachet);
                                      etTigariIntrunPachet.requestFocus();
                                      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                      imm.showSoftInput(etTigariIntrunPachet, InputMethodManager.SHOW_IMPLICIT);
                                      imm.hideSoftInputFromWindow(etTigariIntrunPachet.getWindowToken(), 0);
                                  }
  
                                  EditText etCostPachet = findViewById(R.id.etCostPerPachet);
                                  if (etCostPachet.getText().toString().length() == 0)
                                      etCostPachet.setError(&quot;Valid number is required !&quot;);
                                  else {
                                      String stringCostPachet = etCostPachet.toString();
                                      SharedPreferences.Editor editorCostPachet = settings.edit();
                                      editorCostPachet.putString(&quot;CostPachet&quot;, stringCostPachet);
                                      editorCostPachet.apply();
                                      Context context = getApplicationContext();
                                      Toast.makeText(context, &quot;New configuration was SAVED !&quot;, Toast.LENGTH_LONG).show();
                                      String saveCostPachet = preferences.getString(&quot;CostPachet&quot;, null);
                                      etCostPachet.setText(saveCostPachet);
                                      etCostPachet.requestFocus();
                                      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                      imm.showSoftInput(etCostPachet, InputMethodManager.SHOW_IMPLICIT);
                                      imm.hideSoftInputFromWindow(etCostPachet.getWindowToken(), 0);
                                  }
  
                                  dialog.dismiss();
                              }
                          });
  
                          builder.setNegativeButton(&quot;No&quot;, new DialogInterface.OnClickListener() {
  
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
  
                                  // Do nothing
                                  dialog.dismiss();
                              }
                          });
  
                          AlertDialog alert = builder.create();
                          alert.show();
  
                      }
  
                  });
  
  
      }
  
      private void handleDateButton() {
          Calendar calendar = Calendar.getInstance();
          preferences = getSharedPreferences(&quot;settings_values&quot;, MODE_PRIVATE);
          SharedPreferences settings = getSharedPreferences(&quot;settings_values&quot;, 0);
  
          int an = calendar.get(Calendar.YEAR);
          int luna = calendar.get(Calendar.MONTH);
          int zi = calendar.get(Calendar.DATE);
          DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
  
              @Override
              public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
  
                  TextView showDateResult = findViewById(R.id.showTheDateSetted);
  
                  Calendar calendarFormatted = Calendar.getInstance();
                  calendarFormatted.set(Calendar.YEAR, year);
                  calendarFormatted.set(Calendar.MONTH, month);
                  calendarFormatted.set(Calendar.DATE, dayOfMonth);
  
                  CharSequence dateCharSequence = DateFormat.format(&quot;dd MM yyyy&quot;, calendarFormatted);
                  showDateResult.setText(&quot;You quit smoking on : &quot; + dateCharSequence);
  
                  SharedPreferences.Editor editor = settings.edit();
                  String prefData = dateCharSequence.toString();
  
  
                  SimpleDateFormat myFormat = new SimpleDateFormat(&quot;dd MM yyyy&quot;);
                  Date date = new Date();
                  String secondDate = myFormat.format(date);        //azi
  
  
                  try {
                      Date startDate = myFormat.parse(prefData);
                      Date endDate = myFormat.parse(secondDate);
                      long diff = endDate.getTime() - startDate.getTime();
  
                      if (diff &lt; 0) {
  
                          editor.putString(&quot;Date&quot;, secondDate);
                          editor.apply();
                          showDateResult.setText(&quot;You quit smoking on : &quot; + secondDate);
                          Context context = getApplicationContext();
                          Toast.makeText(context, &quot;Can't be in the future&quot;, Toast.LENGTH_SHORT).show();
  
                      } else {
                          editor.putString(&quot;Date&quot;, prefData);
                          editor.apply();
                      }
  
                  } catch (ParseException e) {
                      e.printStackTrace();
                  }
  
              }
  
  
          }, an, luna, zi);
  
          datePickerDialog.show();
  
  
      }
  
      public boolean onTouchEvent(MotionEvent touchevent) {
          switch (touchevent.getAction()) {
              case MotionEvent.ACTION_DOWN:
                  x1 = touchevent.getX();
                  y1 = touchevent.getY();
                  break;
              case MotionEvent.ACTION_UP:
                  ;
                  x2 = touchevent.getX();
                  y2 = touchevent.getY();
                  if (x1 &lt; x2) {
                      Intent i = new Intent(Settings.this, MainActivity.class);
                      startActivity(i);
                  }
                  break;
          }
          return false;
      }
  
  }```
  </code></pre>