Created a simple application consisting of 2 activities and 1 intent.

MainActivity:

public class CreateMessageActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_message); } public void onSendMessage(View view){ EditText message = (EditText) findViewById(R.id.message); String messageTxt = message.getText().toString(); Intent intent = new Intent(this,RecieveMessageActivity.class); intent.putExtra(RecieveMessageActivity.EXTRA_MESSAGE,messageTxt); startActivity(intent); } } 

Markup for EditText:

 <EditText android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/send" android:layout_below="@+id/send" android:layout_marginTop="18dp" android:ems="10" /> 

Host Activity:

 public class RecieveMessageActivity extends AppCompatActivity { public static final String EXTRA_MESSAGE = "message"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_recieve_message); Intent intent = getIntent(); String text = intent.getStringExtra(EXTRA_MESSAGE); TextView recievedMessage = (TextView) findViewById(R.id.message); recievedMessage.setText(text); } } 

As a result, messages are transmitted and displayed in the second activity, but numbers are entered instead of letters. In the screenshot above, the q and w buttons were entered, which resulted in 8 digits.

enter image description here

Please tell me what could be the catch?

  • one
    I propose to immediately divide the task into three parts and determine where the problem is. messageTxt in the first activation and text in the second. - tse
  • The idea is good, but there is a small BUT. in simple Java, I used the classes Syste.out.println (); how to output to the log in the android studio? in google they write that there is a LogCat, but it shows general information and I do not quite understand how to set it on the output of the data we need .. - Iga
  • @Iga is also possible here, sout also works. - Maxgmer
  • 2
    @Iga, How to work with LogCat . - post_zeew
  • 2
    Log.d("happy", "твое сообщение '" + messageTxt + "'"); Since the word happy is vanishingly small in the log, it is convenient to filter by it. - tse

1 answer 1

It's hard not to notice that 0439 is q, and 0446 is w in Unicode. If you are using Windows, change the encoding of Android Studio from UTF-8 to windows-1252.

  • And how the encoding on the host can affect the work with the string in the application ?? It is created on the device, and on the device is displayed, no hard-coded text, which could be in the wrong encoding. Explain. - tse
  • I changed the MainActivity coding with utd-8 to the one you specified (I also tried 1251 for the experiment). The result is the same .. - Iga
  • This is a problem in the phone, I did the same for myself and everything works for me. Can you tell what phone you are using, firmware and keyboard? - Arnis Shaykh
  • I use Geany Motion (because the processor is amd). I created 2 phones in it: motorolla moto x api-17 4.2.2 and custom phone 4.2.2. on both problems with typing. - Iga
  • I suspect the problem is jeni motion. I have exactly such code works without errors. Do you have a physical device to test? - Arnis Shaykh