1.普通Intent跳转
Intent intent_intent = new Intent(MainActivity.this,IntentActivity.class); startActivity(intent_intent);
2.属性:组件名称:
ComponentName,
action
,data,
category,
flag
public void onClick(View v) {
Intent intent = new Intent();
Intent intent2 = new Intent(IntentActivity.this,IntentRecieveActivity.class);
switch (v.getId()){
case R.id.btn_forresult:
//开启视图,并携带code,等待返回数据
startActivityForResult(intent2,0x60);
break;
case R.id.btn_tel: //打电话
intent.setAction(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:5656565"));
startActivity(intent);
break;
case R.id.btn_sms://发短信
intent.setAction(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("smsto:"+10086));
intent.putExtra("sms_body","welcome to andriod");
startActivity(intent);
break;
case R.id.btn_view://跳转url页面
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("https://blog.csdn.net/yangshuangyue/article/details/51910083"));
startActivity(intent);
break;
case R.id.btn_com: //组件名称跳转
intent.setClassName("com.qp.fragmenttest","com.qp.fragmenttest.ViewPageActivity");
startActivity(intent);
break;
case R.id.btn_cat://categroy:初始化,关闭跳转主屏幕
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
startActivity(intent);
break;
case R.id.btn_flag: //标志,不带历史纪录
intent2.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent2);
break;
case R.id.btn_bigpic:
intent.setAction(Intent.ACTION_VIEW);
startActivity(intent);
break;
default:
break;
}
}
3.打电话和发短信需要权限
<uses-permission android:name="android.permission.CALL_PHONE" /> <uses-permission android:name="android.permission.SEND_SMS" />
4.Intent过滤器
intent-filter:包括action和data category
<activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>