簡體   English   中英

使用具有不同活動和最終電子郵件意圖的多個意圖

[英]Using Multiple intents with different activities and final email intent

我正在制作一個收集信息並通過電子郵件發送的表單應用程序。 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);
        }
    });

}

}

這是將發送電子郵件的最終協議活動。 但是郵件主題行中的最終結果是“您的電話號碼為空”

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


        }


    });
}

}

在您的 AgreementActivity 中,使用以下方法獲取電話號碼:

final String phoneNumber = getIntent().getStringExtra("phoneMessage");

我會像這樣擴展應用程序類,但是您可以找到其他方法。 如果有人導航返回箭頭,您確實需要考慮backstack

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM