Android --- 进程(三)---自定义权限

来源:互联网 发布:Python爬取公众号 编辑:程序博客网 时间:2024/06/05 03:30

自定义权限

可以在 manifest 中 <application> 标签外使用 <permission> 申明自己的权限<permission    android:name="com.xykj.permission.MUSIC"    android:icon="@mipmap/ic_launcher"    android:protectionLevel="normal"    android:label=" 媒体播放权限 "    android:description="@string/permission_des"/>    android:name 权限标识    android:description 权限的描述(详细描述)    android:icon 权限的显示图标    android:label 权限的短描述    android:protectionLevel 权限等级

等级

nomal :普通等级,一般只需要在 manifest 中使用 <use-permission 声明就可以使用dangerous :危险等级signature :只针对同一个证书签名的 appsignatureOrSystem :只针对同一个证书签名的 app 或者系统 app

使用权限,可以在 manifest 中 application 标签内的任何组件标签上使用 android:permission

<service    android:name=".MusicService"    android:enabled="true"    android:exported="true"    android:permission="com.xykj.permission.MUSIC">    <intent-filter>        <action android:name="com.xykj.ACTION_MUSIC" />    </intent-filter></service>

应用多线程

每个进程运行时多少会有些限制 ( 如运行内存 ) ,当应用业务比较复杂时单进程无法满足需求的情况下,需要开启多进程,开启方式,可以在组件上使用
android:process 属性声明进程即可这样就可以将组件运行到对应的进程下

1 、私有进程:进程名称以 “:” 开头,如以下应用的包名为 com.xykj.musicserver

<service    android:name=".MyService1"    android:enabled="true"    android:exported="true"    android:process=":abc" />进程全名为 com.xykj.musicserver:abc

2 、全局进程,进程名全部为字母加 “.” 连接

<service    android:name=".MyService2"    android:enabled="true"    android:exported="true"    android:process="com.abc.test"></service>进程名称为 com.abc.test

多进程应用中 Application 将会被创建多次 ( 一个进程创建一个 Application) ,所以 Application 保存全局变量将会在其他进程中无法取到, static 修饰的类或者变量也将不能在其他进程中访问

原创粉丝点击