活动跳转部分代码显式intent
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_layout);
Button button1=(Button)findViewById(R.id.button_1);
button1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//Toast.makeText(FirstActivity.this,"You clicked Button 1",
// Toast.LENGTH_SHORT).show();
Intent intent=new Intent(FirstActivity.this,SecondActivity.class);
startActivity(intent);
}
});
}
隐式intent跳转,设置category
public void onClick(View v){
//Toast.makeText(FirstActivity.this,"You clicked Button 1",
// Toast.LENGTH_SHORT).show();
Intent intent=new Intent("com.example.hs769.activitytest.ACTION_START");
intent.addCategory("com.example.hs769.activitytest.MY_CATEGORY");
startActivity(intent);
}
<intent-filter>
<action android:name="com.example.hs769.activitytest.ACTION_START"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="com.example.hs769.activitytest.MY_CATEGORY"/>
</intent-filter>
开浏览器
<activity android:name=".ThirdActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http"/>
</intent-filter>
</activity>
public void onClick(View v){
//Toast.makeText(FirstActivity.this,"You clicked Button 1",
// Toast.LENGTH_SHORT).show();
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.baidu.com"));
//intent.addCategory("com.example.hs769.activitytest.MY_CATEGORY");
startActivity(intent);
}
利用intent向活动传参,正向
public void onClick(View v){
String data="Hello SecondActivity";
Intent intent=new Intent(FirstActivity.this,SecondActivity.class);
intent.putExtra("extra_data",data);
startActivity(intent);
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second_layout);
Intent intent=getIntent();