两个Activity之间的转换和值传递和发短信程序

来源:互联网 发布:淘宝店铺生成app 编辑:程序博客网 时间:2024/06/14 18:26

public class Activity02 extends Activity implements OnClickListener {
 private Button myButton = null;
 private TextView myTextView = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        myTextView = (TextView)this.findViewById(R.id.mainTextView);
        myTextView.setText(R.string.main);
        myButton = (Button)this.findViewById(R.id.myButton);
        myButton.setText("点击转向第二个页面");
        myButton.setOnClickListener(this);
      
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity02, menu);
        return true;
    }


 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
 
 /* Intent intent = new Intent();
  intent.putExtra("testIntent", "laizhibing");
  intent.setClass(Activity02.this,OtherActivity.class);
  Activity02.this.startActivity(intent);
 */
  
 //下面是发短信的代码
  Uri uri = Uri.parse("smsto://00000123");
  Intent intent = new Intent(Intent.ACTION_SENDTO,uri);
  intent.putExtra("sms_body", "zhibing");
  Activity02.this.startActivity(intent);
  
 }
   
}

 

OtherActivity

public class OtherActivity extends Activity {
 private TextView textView = null;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_other);
  Intent intent = getIntent();
  String value = intent.getStringExtra("testIntent");
  textView = (TextView)this.findViewById(R.id.otherTextview);
  textView.setText(value);
  //textView.setText(R.string.otherText);
 }

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.other, menu);
  return true;
 }

}