Android 工作室 getIntent().getStringExtra() returns 空

Android studio getIntent().getStringExtra() returns null

我想将值从一个 activity 发送到另一个。

值从这第一个发送Activity:

 // Tout est Ok
Intent intent = new Intent(getApplicationContext(), SetNewPassword.class);
intent.putExtra("number", phone);

startActivity(intent);
finish(); 

我想在这一秒 Activity 中接收值,但是当我尝试在 toast 中显示该值时它显示 null:

phone = getIntent().getStringExtra("number");

Toast.makeText(SetNewPassword.this, phone, Toast.LENGTH_SHORT).show();

 // get the text to pass
    EditText editText = (EditText) findViewById(R.id.editText);
    String textToPass = editText.getText().toString();

    // start the SecondActivity
    Intent intent = new Intent(this, SecondActivity.class);
    intent.putExtra(Intent.EXTRA_TEXT, textToPass);
    startActivity(intent);

秒Activity

   // get the text from MainActivity
    Intent intent = getIntent();
    String text = intent.getStringExtra(Intent.EXTRA_TEXT);

你的数据类型有问题。检查这个或分享你的完整代码。