首页 文章 精选 留言 我的

精选列表

搜索[android things],共10000篇文章
优秀的个人博客,低调大师

自己用到的Android 双服务保活(适配8.0)

最近开发的时候,测试小伙伴经常来找我,“为什么咱家程序放到后台,聊了会qq就得重启了呢?”我脑门一亮,“稍等,一会给你”。然后我就进入了程序流氓(进程保活)之旅。 对于进程保活,其实吧,现在对于MIUI、EMUI等等许多高度定制的系统并没有100%的保活方案,该死还是死掉,但是做了一定的操作,还是可以适当的提高存活的。如下就是我用到的保活方案。 1、启动软件的时候激活本地服务和远程服务 startService (new Intent (this, MainService.class)); startService (new Intent (this, RemoteService.class)); 2、本地服务代码 /** * content:后台运行的服务 * Actor:韩小呆 * Time:2018/5/3 */ public class MainService extends Service { MyBinder binder; MyConn conn; @Override public IBinder onBind(Intent intent) { return binder; } @Override public void onCreate() { super.onCreate(); binder = new MyBinder(); conn = new MyConn(); } class MyBinder extends IMyAidlInterface.Stub { @Override public String getServiceName() throws RemoteException { return MainService.class.getSimpleName(); } } @Override public int onStartCommand(Intent intent, int flags, int startId) { this.bindService(new Intent(MainService.this, RemoteService.class), conn, Context.BIND_IMPORTANT); return START_STICKY; } class MyConn implements ServiceConnection { @Override public void onServiceConnected(ComponentName name, IBinder service) { } @Override public void onServiceDisconnected(ComponentName name) { Intent intent = new Intent(MainService.this, RemoteService.class); if (Build.VERSION.SDK_INT >= 26) { \\适配8.0机制 MainService.this.startForegroundService(intent); } else { MainService.this.startService(intent); } //绑定远程服务 MainService.this.bindService(new Intent(MainService.this, RemoteService.class), conn, Context.BIND_IMPORTANT); } } @Override public void onDestroy() { super.onDestroy(); Intent intent = new Intent(MainService.this, RemoteService.class); \\适配8.0机制 if (Build.VERSION.SDK_INT >= 26) { MainService.this.startForegroundService(intent); } else { MainService.this.startService(intent); } MainService.this.bindService(new Intent(MainService.this, RemoteService.class), conn, Context.BIND_IMPORTANT); } } 3、远程服务代码 /** * content:后台运行的服务 * Actor:韩小呆 * Time:2018/5/3 */ public class RemoteService extends Service { MyConn conn; MyBinder binder; @Override public IBinder onBind(Intent intent) { return binder; } @Override public void onCreate() { super.onCreate(); conn = new MyConn(); binder = new MyBinder(); } @Override public int onStartCommand(Intent intent, int flags, int startId) { this.bindService(new Intent(this, MainService.class), conn, Context.BIND_IMPORTANT); return START_STICKY; } class MyBinder extends IMyAidlInterface.Stub { @Override public String getServiceName() throws RemoteException { return RemoteService.class.getSimpleName(); } } class MyConn implements ServiceConnection { @Override public void onServiceConnected(ComponentName name, IBinder service) { } @Override public void onServiceDisconnected(ComponentName name) { Intent intent = new Intent(RemoteService.this, MainService.class); //开启本地服务 if (Build.VERSION.SDK_INT >= 26) { \\适配8.0机制 RemoteService.this.startForegroundService(intent); } else { RemoteService.this.startService(intent); } //绑定本地服务 RemoteService.this.bindService(new Intent(RemoteService.this, MainService.class), conn, Context.BIND_IMPORTANT); } } @Override public void onDestroy() { super.onDestroy(); Intent intent = new Intent(RemoteService.this, MainService.class); //开启本地服务 if (Build.VERSION.SDK_INT >= 26) { \\适配8.0机制 RemoteService.this.startForegroundService(intent); } else { RemoteService.this.startService(intent); } //绑定本地服务 RemoteService.this.bindService(new Intent(RemoteService.this, MainService.class), conn, Context.BIND_IMPORTANT); } } 4、创建AIDL实现远近程服务通信 // Declare any non-default types here with import statements interface IMyAidlInterface { String getServiceName(); } AIDL文件

优秀的个人博客,低调大师

【Jenkins】Android build failed:build pending,Why did the Gradle Daemon ...

1、问题现象 1.1、Slave went offline during the build 1.2、useNewCruncher has been deprecated. It will be removed in a future version of the gradle plugin. New cruncher is now always enabled. Incremental java compilation is an incubating feature. 2、问题分析&定位 从上诉两个log日志信息来看,有两种可能: 1、gradle 在构建过程中,Jenkins slave agent 的daemon异常,导致slave offline,从而build failed 2、引入了其他的Java编译方式,及一些被deprecated的api 那么我就依据初步分析的这两个可能问题去Google 3、问题解决 3.1、依据Google中各路大神对第二个问题的解析,并根据解决方案进行尝试,均无功而返。 3.2、参考Stack Overflow中对:“Why did the Gradle Daemon die?”的文章中,大神是这样解答的: Gradle build daemon disappeared unexpectedlymost frequently occurs when something else kills the long-running Gradle Daemon process and the client process (the Daemon uses local TCP connections to communicate) tries to send a message and gets no response. For example, runninggradle --stoporkillall javawhile a build is occurring will reproduce this problem. 附文章链接:https://stackoverflow.com/questions/29660238/why-did-the-gradle-daemon-die

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册