2017-12-29 15 views
1

정보를 수집하고 전자 메일로 보내는 양식 앱을 만들고 있습니다. MainActivity는 전화 #을 수집 한 다음 경고 메시지 활동을 수집 한 다음 이름 활동 등을 수집합니다. 문제는 EditText 필드에서 수집 한 데이터를 최종 AgreementActivity로 보내 전자 메일이 작동하지 않는 것입니다. 나는 어디에서나 보았지만 입력 데이터를 최종 합의 활동으로 보내는 동안 사용자를 다음 활동으로 보내는 방법을 알 수 없으므로 전자 메일로 보낼 수 있습니다.다른 활동 및 최종 이메일 의도가있는 다중 의도 사용

이것은 내가 지금까지 가지고있는 것입니다.

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

} 

}

이이 이메일을 보내드립니다 최종 계약 활동입니다. 은 그러나 이메일 제목에 최종 결과는} 당신의 AgreementActivity에서

+0

이 질문에 대한 답변이 명확하지 않습니다. –

+0

3 개가 아닌 하나의 활동이 있으면 훨씬 간단합니다. 그 말은 ... 'phoneNumber.putExtra ("phoneMessage", phoneField.getText(). toString())'에서, 여러분은 여분의 이름'phoneMessage'를'Intent'에 첨부하고 있습니다. 값은'String'입니다. 'intent.getBundleExtra ("phoneMessage")'에서, 당신은 여분으로'phoneMessage'라는'Bundle'을 검색하려고 시도하고 있습니다. 그러나'phoneMessage'라는 이름의'Bundle '은 없다. [Kehinde가 지적한대로 (https://stackoverflow.com/a/48029750/115145), getBundleExtra()가 아닌'getStringExtra()'를 사용해야합니다. – CommonsWare

+0

네, 스크롤 된 하나의 활동이 더 쉬웠을 것이라는 데 동의하지만, 사용자가 한 번에 한 화면에 정보를 입력해야하므로 여러 가지 활동을 수행했습니다. 더 좋은 방법이있을 것이라고 확신합니다. 나는 단지 1 개월 동안 코딩하고있다. –

답변

1

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


     } 


    }); 
} 

"전화 번호가 null"입니다 사용하여 전화 번호를 얻을 :

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

+0

번들 대신이 코드를 사용했으나 마지막 활동에 도달하고 이메일을 실행하면 문자열은 여전히 ​​Null로 나타납니다 –

+0

@JoshuaEdgar하지만 AgreementActivity가 최종 활동권입니까? –

+0

예. 나는 8 개의 활동을 모두 가지고있다. 주 활동 (전화 번호)과 계약 활동 (다른 모든 활동에서 얻은 정보를 제출하는 곳) 만 표시합니다. –

0

I을 그러나 다른 방법을 찾을 수있는 신청 class like this를 확장 할 것입니다. 누군가가 뒤로 화살표를 탐색하면 the backstack을 고려해야합니다.