Java 使用不同活动的多个意图和最终电子邮件意图

Java 使用不同活动的多个意图和最终电子邮件意图,java,android,email,android-intent,android-activity,Java,Android,Email,Android Intent,Android Activity,我正在制作一个表单应用程序,收集信息并通过电子邮件发送。MainActivity收集电话#,然后发送到警告消息活动,然后发送到命名活动等。我遇到的问题是将从EditText字段收集的数据发送到最终协议活动,以电子邮件的形式发送,这对我不起作用。我到处都找过了,但我不知道如何将用户发送到下一个活动,同时将输入数据发送到最终协议活动,以便通过电子邮件发送 这就是我目前所拥有的 public class MainActivity extends AppCompatActivity { @Overr

我正在制作一个表单应用程序,收集信息并通过电子邮件发送。MainActivity收集电话#,然后发送到警告消息活动,然后发送到命名活动等。我遇到的问题是将从EditText字段收集的数据发送到最终协议活动,以电子邮件的形式发送,这对我不起作用。我到处都找过了,但我不知道如何将用户发送到下一个活动,同时将输入数据发送到最终协议活动,以便通过电子邮件发送

这就是我目前所拥有的

 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);
        }
    });

}
}

这是最终协议活动,它将在其中发送电子邮件。 但电子邮件主题行的最终结果是“您的电话号码为空”


}

在协议活动中,使用以下方法获取电话号码:


final String phoneNumber=getIntent().getStringExtra(“phoneMessage”)

我会扩展应用程序,但您可以找到其他方法。你需要考虑如果有人导航返回箭头

不清楚这是什么要求。如果你有一个活动而不是三,这会简单得多。话虽如此。。。在
phoneNumber.putExtra(“phoneMessage”,phoneField.getText().toString())
中,您正在将一个名为
phoneMessage
的额外文件附加到
意图中。该值是一个
字符串
。在
intent.getBundleExtra(“phoneMessage”)
中,您试图检索名为
phoneMessage
捆绑包作为额外信息。但是,没有名为
phoneMessage
Bundle
。因此,您需要使用
getStringExtra()
,而不是
getBundleExtra()
。是的,我同意滚动一个活动会更容易,但因为我希望用户一次只在表单屏幕上输入一个信息,所以我进行了多个活动。我相信有更好的办法。虽然我只编写了1个月的代码,我使用了这段代码而不是bundle,但是当我到达最后一个活动并启动email@JoshuaEdgar但协议活动是最终活动,对吗?是的。我一共有8项活动。我只显示主要活动(电话号码),然后是协议活动(在这里提交从所有其他活动获得的信息)@JoshuaEdgar,因为AgreementActivity是从主要活动启动的,那么phoneMessage不应该为空。是否有可能在用户进入最终活动之前,EditText字段中的输入文本已被销毁,因为它没有被带入其间的所有活动?
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);
            }


        }


    });
}