一个Intent对象包含了一组信息:
可以启动另一个Activiy:
Activity02.this.startActivity(intent);
视频中有句代码应改为
class MyButtonListener implements android.view.View.OnClickListener{
}
activity02.java中的代码应该为
package bxl.activity_02;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class Activity02 extends Activity {
private Button myButton = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity02);
myButton = (Button)findViewById(R.id.myButton);
myButton.setText(R.string.app_name);
myButton.setOnClickListener(new MyButtonListener());
}
class MyButtonListener implements android.view.View.OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//生成一个Intent对象
Intent intent = new Intent();
intent.setClass(Activity02.this, OtherActivity.class);
Activity02.this.startActivity(intent);
}
}
}
Intent可以调用不同应用程序中的Activity
发短信:
Uri uri=Uri.parse("smsto://18086241796");
Intent intent=new Intent(Intent.ACTION_SENDTO,uri);
intent.putExtra("sms_body", "The SMS text");
startActivity(intent);