目录:
1、Service
2、AndroidManifest
3、Github搜索技巧
4、AndroidStudio主题设置
Android小仙
1. Service
Service lifeCycle从上图可以看到,
onStart()
方法被onStartCommand()
方法取代了。那么问题来了,
onStart()
和onStartCommand()
的区别是什么呢?onStart()
是android2.0以下的版本使用的,而onStartCommand()
则是android2.0以上的版本使用的。两个可以同时使用不会有冲突,执行的时候先调用
onStartCommand()
,再调用onStart()
。
1.1. onStartCommand()
方法
public @StartResult int onStartCommand(Intent intent, @StartArgFlags int flags, int startId) {
onStart(intent, startId);
return mStartCompatibility ? START_STICKY_COMPATIBILITY : START_STICKY;
}
主要看四种返回值类型
- START_STICKY:如果service进程被kill掉,保留service的状态为开始状态,但不保留递送的intent对象。随后系统会尝试重新创建service,由于服务状态为开始状态,所以创建服务后一定会调用onStartCommand(Intent,int,int)方法。如果在此期间没有任何启动命令被传递到service,那么参数Intent将为null。
- START_NOT_STICKY:“非粘性的”。使用这个返回值时,如果在执行完onStartCommand后,服务被异常kill掉,系统不会自动重启该服务
- START_REDELIVER_INTENT:重传Intent。使用这个返回值时,如果在执行完onStartCommand后,服务被异常kill掉,系统会自动重启该服务,并将Intent的值传入。
- START_STICKY_COMPATIBILITY:START_STICKY的兼容版本,但不保证服务被kill后一定能重启。
1.2. Service永不被kill的方法
- 将service优先级设置到最高,1000
- onStartCommand return START_STICKY
- 在Service的onDestroy中,发送广播重启自己
- 设置android:persistent="true"
- Service提升为前台进程级别
就是在onStartCommand里面调用 startForeground()方法把Service提升为前台进程级别,然后再onDestroy里面要记得调用stopForeground ()方法。
1.3. 相对强大的进程保活方案
参考资料:
双进程守护,驻留,杀不死服务:MarsDaemon
其他:参考同类APP的做法,如:<a>闪铃</a>
1.4. 用户配置保活
- 设置悬浮窗
- 设置自启动
- 设置常驻服务
- 设置允许高耗电
2. AndroidManifest
2.1. Application节点说明
先上例子
<application
android:name=".MyApplication"
android:allowBackup="true"
android:allowClearUserData="false"
android:excludeFromRecents="true"
android:hardwareAccelerated="true"
android:largeHeap="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:persistent="true"
android:theme="@style/AppTheme" >
</application>
简单的不说,来看看下面的
-
android:allowBackup="true"
允许应用程序参与备份。如果将该属性设置为false,则即使备份整个系统,也不会执行这个应用程序的备份操作,而整个系统备份能导致所有应用程序数据通过ADB来保存。其默认值为true。 -
android:excludeFromRecents="true"
使应用从最近使用应用列表中剔除 -
android:hardwareAccelerated="true"
使用硬件加速功能。指示硬件加速渲染功能是否对应用程序中的所有Activity和View启用。其默认值是false。 -
android:persistent="true"
将应用设置为永久性应用,开机自启。实质就是拥有persistent=true属性的app将不能被kill或kill后会自动重启。其默认值是false。 -
android:largeHeap="true"
此属性指示应用程序是否使用一个比较大的堆创建。它的默认值是false。 -
android:supportsRtl=true
:支持屏幕从右到左
参考资料:Android清单文件详解(五)----<application>的属性详解
2.2. 创建桌面快捷方式适配不同机型
各个手机产商自定义的创建桌面快捷方式的权限
参考:Permissions used in Alipay 9.6.6
uses-permission: name='com.alipay.permission.ALIPAY_UPDATE_CREDENTIALS'
uses-permission: name='com.android.launcher.permission.INSTALL_SHORTCUT'
uses-permission: name='android.permission.BLUETOOTH'
uses-permission: name='android.permission.CHANGE_WIFI_STATE'
uses-permission: name='android.permission.CAMERA'
uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
uses-permission: name='android.permission.MODIFY_AUDIO_SETTINGS'
uses-permission: name='com.yunos.permission.TYID_MGR_SERVICE'
uses-permission: name='android.permission.RECEIVE_SMS'
uses-permission: name='android.permission.AUTHENTICATE_ACCOUNTS'
uses-permission: name='com.alipay.permission.ALIPAY_USE_CREDENTIALS'
uses-permission: name='com.aliyun.permission.TYID_MGR_SERVICE'
uses-permission: name='android.permission.BATTERY_STATS'
uses-permission: name='android.permission.READ_PHONE_STATE'
uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
uses-permission: name='android.permission.NFC'
uses-permission: name='android.permission.RECORD_AUDIO'
uses-permission: name='android.permission.READ_SMS'
uses-permission: name='com.taobao.permission.UPDATE_CREDENTIALS'
uses-permission: name='com.yunos.permission.STORAGE_SERVICE'
uses-permission: name='com.sonyericsson.home.permission.BROADCAST_BADGE'
uses-permission: name='com.android.launcher.permission.UNINSTALL_SHORTCUT'
uses-permission: name='android.permission.READ_CONTACTS'
uses-permission: name='android.permission.USE_CREDENTIALS'
uses-permission: name='android.permission.VIBRATE'
uses-permission: name='com.yunos.permission.TYID_SERVICE'
uses-permission: name='android.permission.ACCESS_FINE_LOCATION'
uses-permission: name='android.permission.FLASHLIGHT'
uses-permission: name='com.taobao.permission.USE_CREDENTIALS'
uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
uses-permission: name='android.permission.MANAGE_ACCOUNTS'
uses-permission: name='android.permission.CALL_PHONE'
uses-permission: name='android.permission.READ_LOGS'
uses-permission: name='android.permission.GET_ACCOUNTS'
uses-permission: name='android.permission.GET_TASKS'
uses-permission: name='android.permission.ACCESS_WIFI_STATE'
uses-permission: name='com.android.launcher.permission.READ_SETTINGS'
uses-permission: name='com.htc.launcher.permission.READ_SETTINGS'
uses-permission: name='com.majeur.launcher.permission.UPDATE_BADGE'
uses-permission: name='com.aliyun.permission.TYID_SERVICE'
uses-permission: name='android.permission.WAKE_LOCK'
uses-permission: name='android.permission.BLUETOOTH_ADMIN'
uses-permission: name='android.permission.RECEIVE_BOOT_COMPLETED'
uses-permission: name='android.permission.INTERNET'
uses-permission: name='android.permission.SYSTEM_ALERT_WINDOW'
uses-permission: name='com.htc.launcher.permission.UPDATE_SHORTCUT'
uses-permission: name='android.permission.WRITE_SETTINGS'
uses-permission: name='com.anddoes.launcher.permission.UPDATE_COUNT'
uses-permission: name='android.permission.READ_PROFILE'
uses-permission: name='android.permission.BROADCAST_STICKY'
uses-permission: name='com.aliyun.permission.STORAGE_SERVICE'
uses-permission: name='nxp.permission.ACCESS_WALLET_SERVICE'
uses-permission: name='com.samsung.android.authservice.permission.READ_CONTENT_PROVIDER'
uses-permission: name='android.permission.USE_FINGERPRINT'
uses-permission: name='android.permission.MANAGE_FINGERPRINT'
permission: com.eg.android.AlipayGphone.permission.MIPUSH_RECEIVE
uses-permission: name='com.eg.android.AlipayGphone.permission.MIPUSH_RECEIVE'
uses-permission: name='com.miui.mihome2.permission.READ_SETTINGS'
uses-permission: name='com.miui.mihome2.permission.WRITE_SETTINGS'
uses-permission: name='com.aliyun.homeshell.permission.WRITE_SETTINGS'
uses-permission: name='com.aliyun.homeshell.permission.READ_SETTINGS'
uses-permission: name='com.lenovo.launcher.permission.READ_SETTINGS'
uses-permission: name='com.lenovo.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.iLoong.permission.WRITE_SETTINGS'
uses-permission: name='com.iLoong.permission.READ_SETTINGS'
uses-permission: name='cn.nubia.launcher.permission.WRITE_SETTINGS'
uses-permission: name='cn.nubia.launcher.permission.READ_SETTINGS'
uses-permission: name='com.smartisanos.launcher.WRITE_DATABASE'
uses-permission: name='com.smartisanos.launcher.READ_DATABASE'
uses-permission: name='com.smartisanos.launcher.data.ExportDataProvider'
uses-permission: name='com.teslacoilsw.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.teslacoilsw.launcher.permission.READ_SETTINGS'
uses-permission: name='com.meizu.flyme.launcher.permission.READ_SETTINGS'
uses-permission: name='com.meizu.flyme.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.ztemt.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.ztemt.launcher.permission.READ_SETTINGS'
uses-permission: name='com.zte.lqsoft.launcher.permission.READ_SETTINGS'
uses-permission: name='com.zte.lqsoft.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.baoruan.launcher2.permission.WRITE_SETTINGS'
uses-permission: name='com.baoruan.launcher2.permission.READ_SETTINGS'
uses-permission: name='com.fineos.launcher.permission.READ_SETTINGS'
uses-permission: name='com.fineos.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.ibingo.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.ibingo.launcher.permission.READ_SETTINGS'
uses-permission: name='com.zui.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.zui.launcher.permission.READ_SETTINGS'
uses-permission: name='com.qihoo360.screenlock.permission.READ_LOCAL_THEME'
uses-permission: name='com.qihoo360.screenlock.permission.WRITE_LOCAL_THEME'
uses-permission: name='com.zte.mifavor.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.zte.mifavor.launcher.permission.READ_SETTINGS'
uses-permission: name='com.lo.launcher.permission.READ_SETTINGS'
uses-permission: name='com.lo.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.android.tpwlauncher2.permission.WRITE_SETTINGS'
uses-permission: name='com.android.tpwlauncher2.permission.READ_SETTINGS'
uses-permission: name='com.android.sprdlauncher1.permission.READ_SETTINGS'
uses-permission: name='com.android.sprdlauncher1.permission.WRITE_SETTINGS'
uses-permission: name='com.s.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.s.launcher.permission.READ_SETTINGS'
uses-permission: name='com.zte.mobile.ZteLauncher3D.permission.READ_SETTINGS'
uses-permission: name='com.zte.mobile.ZteLauncher3D.permission.WRITE_SETTINGS'
uses-permission: name='com.android.launcher23.permission.READ_SETTINGS'
uses-permission: name='com.android.launcher23.permission.WRITE_SETTINGS'
uses-permission: name='com.mgyun.permission.READ_SETTINGS'
uses-permission: name='com.mgyun.permission.WRITE_SETTINGS'
uses-permission: name='com.asus.launcher3.permission.READ_SETTINGS'
uses-permission: name='com.asus.launcher3.permission.WRITE_SETTINGS'
uses-permission: name='com.tsf.shell.permission.READ_SETTINGS'
uses-permission: name='com.tsf.shell.permission.WRITE_SETTINGS'
uses-permission: name='com.tul.aviate.permission.READ_SETTINGS'
uses-permission: name='com.tul.aviate.permission.WRITE_SETTINGS'
uses-permission: name='com.lenovo.launcherhdmarket.permission.READ_SETTINGS'
uses-permission: name='com.lenovo.launcherhdmarket.permission.WRITE_SETTINGS'
uses-permission: name='com.hola.launcher.permission.READ_SETTINGS'
uses-permission: name='com.hola.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.qihoo360.home.permission.WRITE_SETTINGS'
uses-permission: name='com.qihoo360.home.permission.READ_SETTINGS'
uses-permission: name='com.slim.slimlauncher.permission.READ_SETTINGS'
uses-permission: name='com.slim.slimlauncher.permission.WRITE_SETTINGS'
uses-permission: name='com.huaqin.launcherEx.permission.WRITE_SETTINGS'
uses-permission: name='com.huaqin.launcherEx.permission.READ_SETTINGS'
uses-permission: name='com.epic.launcher.tw.permission.WRITE_SETTINGS'
uses-permission: name='com.epic.launcher.tw.permission.READ_SETTINGS'
uses-permission: name='com.android.lewalauncher.permission.READ_SETTINGS'
uses-permission: name='com.android.lewalauncher.permission.WRITE_SETTINGS'
uses-permission: name='com.Dean.launcher.permission.READ_SETTINGS'
uses-permission: name='com.Dean.launcher.permission.WRITE_SETTINGS'
uses-permission: name='app.cobo.launcher.permission.WRITE_SETTINGS'
uses-permission: name='app.cobo.launcher.permission.READ_SETTINGS'
uses-permission: name='com.alphalp.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.alphalp.launcher.permission.READ_SETTINGS'
uses-permission: name='com.lollipop.launcher.permission.READ_SETTINGS'
uses-permission: name='com.lollipop.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.l.launcher.permission.READ_SETTINGS'
uses-permission: name='com.l.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.dlto.atom.launcher.permission.READ_SETTINGS'
uses-permission: name='com.dlto.atom.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.android.sprdlauncher2.permission.WRITE_SETTINGS'
uses-permission: name='com.android.sprdlauncher2.permission.READ_SETTINGS'
uses-permission: name='com.konka.launcher2.permission.READ_SETTINGS'
uses-permission: name='com.konka.launcher2.permission.WRITE_SETTINGS'
uses-permission: name='com.mycheering.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.mycheering.launcher.permission.READ_SETTINGS'
uses-permission: name='com.microsoft.launcher.permission.READ_SETTINGS'
uses-permission: name='com.microsoft.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.nicelauncher.lolauncher.permission.READ_SETTINGS'
uses-permission: name='com.nicelauncher.lolauncher.permission.WRITE_SETTINGS'
uses-permission: name='com.jui.launcher3.permission.READ_SETTINGS'
uses-permission: name='com.jui.launcher3.permission.WRITE_SETTINGS'
uses-permission: name='com.android.launcher2.permission.READ_SETTINGS'
uses-permission: name='com.android.launcher2.permission.WRITE_SETTINGS'
uses-permission: name='com.qihoo360.launcher.permission.READ_SETTINGS'
uses-permission: name='com.qihoo360.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.lge.launcher.permission.READ_SETTINGS'
uses-permission: name='com.lge.launcher.permission.WRITE_SETTINGS'
uses-permission: name='net.qihoo.launcher.permission.READ_SETTINGS'
uses-permission: name='net.qihoo.launcher.permission.WRITE_SETTINGS'
uses-permission: name='org.adw.launcher_donut.permission.READ_SETTINGS'
uses-permission: name='org.adw.launcher_donut.permission.WRITE_SETTINGS'
uses-permission: name='com.huawei.launcher3.permission.READ_SETTINGS'
uses-permission: name='com.huawei.launcher3.permission.WRITE_SETTINGS'
uses-permission: name='com.sec.android.app.twlauncher.settings.READ_SETTINGS'
uses-permission: name='com.sec.android.app.twlauncher.settings.WRITE_SETTINGS'
uses-permission: name='com.anddoes.launcher.permission.READ_SETTINGS'
uses-permission: name='com.anddoes.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.tencent.qqlauncher.permission.READ_SETTINGS'
uses-permission: name='com.tencent.qqlauncher.permission.WRITE_SETTINGS'
uses-permission: name='com.huawei.launcher2.permission.READ_SETTINGS'
uses-permission: name='com.huawei.launcher2.permission.WRITE_SETTINGS'
uses-permission: name='com.ebproductions.android.launcher.permission.READ_SETTINGS'
uses-permission: name='com.ebproductions.android.launcher.permission.WRITE_SETTINGS'
uses-permission: name='telecom.mdesk.permission.READ_SETTINGS'
uses-permission: name='telecom.mdesk.permission.WRITE_SETTINGS'
uses-permission: name='dianxin.permission.ACCESS_LAUNCHER_DATA'
uses-permission: name='com.modaco.android.launchergb.permission.READ_SETTINGS'
uses-permission: name='com.modaco.android.launchergb.permission.WRITE_SETTINGS'
uses-permission: name='com.sec.android.app.launcher.permission.READ_SETTINGS'
uses-permission: name='com.sec.android.app.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.bbk.launcher2.permission.READ_SETTINGS'
uses-permission: name='com.bbk.launcher2.permission.WRITE_SETTINGS'
uses-permission: name='com.android.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.htc.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.sec.android.app.twlauncher.WRITE_SETTINGS'
uses-permission: name='com.sec.android.app.twlauncher.READ_SETTINGS'
uses-permission: name='org.adw.launcher.permission.READ_SETTINGS'
uses-permission: name='org.adw.launcher.permission.WRITE_SETTINGS'
uses-permission: name='org.adwfreak.launcher.permission.READ_SETTINGS'
uses-permission: name='org.adwfreak.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.gau.go.launcherex.permission.READ_SETTINGS'
uses-permission: name='com.gau.go.launcherex.permission.WRITE_SETTINGS'
uses-permission: name='com.fede.launcher.permission.READ_SETTINGS'
uses-permission: name='com.fede.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.oppo.launcher.permission.READ_SETTINGS'
uses-permission: name='com.oppo.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.nd.android.launcher.permission.READ_SETTINGS'
uses-permission: name='com.nd.android.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.android.mylauncher.permission.READ_SETTINGS'
uses-permission: name='com.android.mylauncher.permission.WRITE_SETTINGS'
uses-permission: name='com.huawei.android.launcher.permission.READ_SETTINGS'
uses-permission: name='com.huawei.android.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.huawei.launcher.permission.READ_SETTINGS'
uses-permission: name='com.huawei.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.mx.launcher.permission.READ_SETTINGS'
uses-permission: name='com.mx.launcher.permission.WRITE_SETTINGS'
uses-permission: name='com.android.launcher3.permission.READ_SETTINGS'
uses-permission: name='com.android.launcher3.permission.WRITE_SETTINGS'
uses-permission: name='com.google.android.launcher.permission.READ_SETTINGS'
uses-permission: name='com.google.android.launcher.permission.WRITE_SETTINGS'
uses-permission: name='android.permission.MOUNT_UNMOUNT_FILESYSTEMS'
uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
3. Github搜索技巧
- 搜索时星星数量越多越好
- 对应作者的其他项目的反馈情况有参考价值
- 看issues一栏里面已关闭和未关闭的问题
- 翻开库直接看源码查质量
4.AndroidStudio主题设置和字体设置
4.1、设置主题色
Darcula主题是背景色为黑色的主题
Default默认的主题是背景色为白色的主题
设置方法:Android Studio -- Preferences -- Appearance&Behavior -- Appearance -- UI Options --Theme
4.2、字体大小设置
Android Studio -- Preferences -- Editor -- ColorScheme -- ColorSchemeFont -- size
网友评论