Activity详解

Activity 生命周期

 

 

显式 Intent 调用

 

 1     //创建一个显式的 Intent 对象(方法一:在构造函数中指定)
 2                     Intent intent = new Intent(Intent_Demo1.this, Intent_Demo1_Result1.class);
 3                     
 4                     Bundle bundle = new Bundle();
 5                     bundle.putString("id", strID);
 6                     intent.putExtras(bundle);
 7                     
 8                     intent.putExtra("name", "bbb");
 9                     intent.putExtra("userInfo", new UserInfo(1, "name"));
10                     startActivity(intent);
11                     
12                     //创建一个显式的 Intent 对象(方法二:用 setClass 方法)
13                     Intent intent = new Intent();
14                     Bundle bundle = new Bundle();
15                     bundle.putString("id", strID);
16                     intent.setClass(Intent_Demo1.this, Intent_Demo1_Result1.class);
17                     intent.putExtras(bundle);
18                     startActivity(intent);
19                     
20                     //创建一个显式的 Intent 对象(方法三:用 setClass 方法)
21                     Intent intent = new Intent();
22                     Bundle bundle = new Bundle();
23                     bundle.putString("id", strID);
24                     intent.setClassName(Intent_Demo1.this, "com.great.activity_intent.Intent_Demo1_Result1");
25                     intent.putExtras(bundle);
26                     startActivity(intent);
27                     
28                     //创建一个显式的 Intent 对象(方法四:用 setComponent 方法)
29                     Intent intent = new Intent();
30                     Bundle bundle = new Bundle();
31                     bundle.putString("id", strID);
32                     //setComponent方法的参数:ComponentName
33                     intent.setComponent(new ComponentName(Intent_Demo1.this, Intent_Demo1_Result1.class));
34                     intent.putExtras(bundle);
35                     startActivity(intent);

Intent隐式跳转 Action

 1     //创建一个隐式的 Intent 对象:Action 动作
 2     /**
 3      * 这里指定的是 AndroidManifest.xml 文件中配置的
 4      * <intent-filter>标签中的<action android:name="com.great.activity_intent.Intent_Demo1_Result3" />
 5      * 所在的 Activity,注意这里都要设置 <category android:name="android.intent.category.DEFAULT" />
 6      */
 7     Intent intent = new Intent();
 8     //设置 Intent 的动作
 9     intent.setAction("com.great.activity_intent.Intent_Demo1_Result3");
10     Bundle bundle = new Bundle();
11     bundle.putString("id", strID);
12     intent.putExtras(bundle);
13     startActivity(intent);

AndroidManifest.xml

1    <activity android:name="Intent_Demo1_Result3"
2                   android:label="Intent_Demo1_Result3">
3             <intent-filter>
4                 <action android:name="com.great.activity_intent.Intent_Demo1_Result3" />
5                 <category android:name="android.intent.category.DEFAULT" />
6             </intent-filter>
7         </activity>

 

Category 类别

 1 //创建一个隐式的 Intent 对象:Category 类别
 2 Intent intent = new Intent();
 3 intent.setAction("com.great.activity_intent.Intent_Demo1_Result33");
 4 /**
 5  * 不指定 Category 或 只指定 AndroidManifest.xml 文件中 <intent-filter> 标签中配置的任意一个 Category
 6  * <category android:name="android.intent.category.DEFAULT" /> 除外,就可以访问该 Activity,
 7  */
 8 intent.addCategory(Intent.CATEGORY_INFO);
 9 intent.addCategory(Intent.CATEGORY_DEFAULT);
10 Bundle bundle = new Bundle();
11 bundle.putString("id", strID);
12 intent.putExtras(bundle);
13 startActivity(intent);

AndroidManifest.xml

  <activity android:name="Intent_Demo1_Result2"
                  android:label="Intent_Demo1_Result2">
            <intent-filter>
                
                <category android:name="android.intent.category.INFO" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                
            </intent-filter>
        </activity>

Date 数据 跳转

 1 //创建一个隐式的 Intent 对象,方法四:Date 数据
 2 Intent intent = new Intent();
 3 Uri uri = Uri.parse("http://www.great.org:8080/folder/subfolder/etc/abc.pdf");
 4 
 5 //注:setData、setDataAndType、setType 这三种方法只能单独使用,不可共用                
 6 //要么单独以 setData 方法设置 URI
 7 //intent.setData(uri);
 8 //要么单独以 setDataAndType 方法设置 URI 及 mime type
 9 intent.setDataAndType(uri, "text/plain");
10 //要么单独以 setDataAndType 方法设置 Type
11 //intent.setType("text/plain");
12 
13 /**
14  * 不指定 Category 或 只指定 AndroidManifest.xml 文件中 <intent-filter> 标签中配置的任意一个 Category
15  * <category android:name="android.intent.category.DEFAULT" /> 除外,就可以访问该 Activity
16  */
17 Bundle bundle = new Bundle();
18 bundle.putString("id", strID);
19 intent.putExtras(bundle);
20 startActivity(intent);

AndroidManifest.xml

 1         <activity android:name="Intent_Demo1_Result2"
 2                   android:label="Intent_Demo1_Result2">
 3             <intent-filter>
 4                 <category android:name="android.intent.category.DEFAULT" />
 5                 <data 
 6                     android:scheme="http"
 7                     android:host="www.great.org"
 8                     android:port="8080"
 9                     android:pathPattern=".*pdf"
10                     android:mimeType="text/plain"/>
11             </intent-filter>
12         </activity>
13         

 

 

 

 

转载于:https://www.cnblogs.com/totome/archive/2012/09/02/2667844.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值