Android应用开发笔记

讨论了服务在主机进程中的运行方式,服务如何避免ANR,并详细解释了隐式Intent在startActivity方法中的应用及注意事项。

1. A service runs in the main thread of its hosting process—the service does not create its own thread and does not run in a separate process (unless you specify otherwise)

service虽然没有UI,也不可以做耗时操作,否则依旧有ActivityManager报ANR,即使将service设置到另外一个process中也不行,虽然当前process的UI不会阻塞了,可是后台打印log发现,另一个process里的service在大约30s后ANR了。。而且没有ANR的提示框弹出。。。


2.startActivity

<activity
            android:name="com.example.call.MyActivity"
            android:label="@string/app_name2" >
            <intent-filter >
                <action android:name="ritter.com"/>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

当使用隐式调用activity时,一定要在intent-filter里指定category DEFAULT,因为默认的Intent会创建category DEFAULT。

Android treats all implicit intents passed to startActivity() as if they contained at least one category: "android.intent.category.DEFAULT" (the CATEGORY_DEFAULT constant). Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值