私は情報を収集して電子メールで送信するフォームアプリケーションを作成しています。 MainActivityは電話番号を収集し、次に警告メッセージアクティビティ、名前アクティビティなどを収集します。私が問題になっているのは、EditTextフィールドから収集したデータを最終的なAgreementActivityに送信することです。私はどこにでも見てきましたが、入力データを最終的なAgreementアクティビティに送信して電子メールで送信できるように、ユーザを次のアクティビティに送る方法を理解することはできません。さまざまな活動と最終的なメールの意図を持つ複数のインテントの使用
これはこれまで私が行ってきたことです。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Find the next button
final Button next1 = (Button) findViewById(R.id.button);
// Find the Edit Text Field to input Phone Number
final EditText phoneField = (EditText) findViewById(R.id.edit_text_phone);
// Set a click listener on the next button
next1.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the next1 Button is clicked on.
@Override
public void onClick(View view) {
// sends data collected from edit text box to be sent to final page so it can be
// sent in an email message.
Intent phoneNumber = new Intent(MainActivity.this, AgreementActivity.class);
phoneNumber.putExtra("phoneMessage", phoneField.getText().toString());
startActivity(phoneNumber);
//starts next activity
Intent nextButton = new Intent(MainActivity.this, Warning.class);
startActivity(nextButton);
}
});
}
}
これは、電子メールを送信する最終合意活性です。 しかし、電子メールの件名に最終的な結果は、 "あなたの電話番号がnull" でごAgreementActivityで
public class AgreementActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.agreement_activity);
// Find the submit button
final Button submit = (Button) findViewById(R.id.button6);
// This is the input from user for phone number field
final Bundle phoneNumber = getIntent().getExtras();
// Set a click listener on that View
submit.setOnClickListener(new View.OnClickListener() {
// The code in this method will be executed when the Submit Button is clicked on.
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.getBundleExtra("phoneMessage");
intent.putExtra(Intent.EXTRA_SUBJECT, "Your Phone Number is " + phoneNumber);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
});
}
}
これが何であるか不明確です。 –
3つではなく1つのアクティビティがあれば、これははるかに簡単になります。それは... 'phoneNumber.putExtra(" phoneMessage "、phoneField.getText()。toString())'で、 'Intent'に余分な名前の' phoneMessage'を付けています。値は 'String'です。 'intent.getBundleExtra(" phoneMessage ")'では、あなたは余分なものとして 'phoneMessage'という名前の' Bundle'を検索しようとしています。しかし、 'phoneMessage'という名前の' Bundle'はありません。 [Kehindeが指摘するように](https://stackoverflow.com/a/48029750/115145)、 'getStringExtra()'ではなく 'getStringExtra()'を使う必要があります。 – CommonsWare
はい、私は、スクロールされた1つのアクティビティは簡単でしたが、ユーザーが一度にフォームに1つの画面に情報を入力したかったので、私は複数のアクティビティを作成しました。私は良い方法があると確信しています。私は1ヶ月間しかコーディングしていません。 –