Send Variable from one activity to another one
我有一个屏幕,在那里我存储了一个电话号码,然后转到另一个屏幕,启动活动的主要部分,在那里我发送了一个文本按摩,我正在尝试获取我在第一个活动中输入的号码。我已经输入了发送消息的所有代码,但它无法从上一个活动中获取号码。以下是我的第一个活动代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | public class StoreNumberActivity extends Host_Setting_PageActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.on``Create(savedInstanceState); setContentView(R.layout.notificationsettings); final EditText editText= (EditText) findViewById(R.id.HostPhoneNumber); //Juston class to schedule edit Button Save = (Button) findViewById(R.id.SaveBtn); Save.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Toast.makeText(StoreNumberActivity.this,"Number was Saved Successfully", Toast.LENGTH_LONG).show(); } }); Button Send = (Button) findViewById(R.id.SendBtn); Send.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { String Number = editText.getText().toString(); Intent myIntent = new Intent(StoreNumberActivity.this, Host_Setting_PageActivity.class); myIntent.putExtra("Phone Num", Number); startActivity(myIntent); } and my code from the second activity: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /** setting the view of the activity to xml */ setContentView(R.layout.messageme); final Bundle bundle = getIntent().getExtras(); final EditText editText= (EditText) findViewById(R.id.yourname); final EditText phonenumber= (EditText) findViewById(R.id.phone); final EditText emailaddress= (EditText) findViewById(R.id.email); final EditText messagebox= (EditText) findViewById(R.id.messages); final EditText number = (EditText) findViewById(R.id.HostPhoneNumber); button= (Button) findViewById(R.id.btn); button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub Intent myIntent = getIntent(); // this is just for example purpose myIntent.getStringExtra("PhoneNum"); String Number = bundle.getString("Phone Num"); String Name = editText.getText().toString(); String Phone = phonenumber.getText().toString(); String Email = emailaddress.getText().toString(); String Message = messagebox.getText().toString(); sendSMS(Number,"Name:" + Name +" " +" " +"Email:" + Email +" " +" " +"Phone:" + Phone +" " +" " + Message); } |
下面是一些StackOverflow答案,可以为您提供所需的:
在活动Android之间传递值
如何在Android中的活动之间传递数据?