remote导致的application问题

最近接手的项目偶然间发现的一个bug:application的onCreate执行了两次。。。果断去清单文件里面看一下,果然

 <!--百度定位-->
 <service
      android:name="com.baidu.location.f"
      android:enabled="true"
      android:process=":remote"/>

通过log,发现除了包名的进程外,还有一个包名:remote的进行,而多出来的执行数次,就是这个进程在执行的,那么问题就非常好解决了,判断一下进程,只执行正确包名的就妥了。

 public static String getProcessName(Context context, int pid) {
        ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> runningApps = manager.getRunningAppProcesses();
        if (runningApps == null) {
            return null;
        }
        for (ActivityManager.RunningAppProcessInfo procInfo : runningApps) {
            if (procInfo.pid == pid) {
                return procInfo.processName;
            }
        }
        return null;
    }

这是获取进程名的一个方法
然后在application的资源初始化之前,加入判断:

 String processName = SinMinUtils.getProcessName(this, android.os.Process.myPid());
  if (!getPackageName().equals(processName)) {
        return;
      }

解决。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Failed to invoke the method sendMessage in the service com.itbz.shopping_common.service.MessageService. Tried 3 times of the providers [192.168.66.10:20880] (1/1) from the registry 192.168.66.159:2181 on the consumer 192.168.119.1 using the dubbo version 2.7.8. Last error is: Invoke remote method timeout. method: sendMessage, provider: dubbo://192.168.66.10:20880/com.itbz.shopping_common.service.MessageService?anyhost=true&application=shopping_user_customer_api&check=false&deprecated=false&dubbo=2.0.2&dynamic=true&generic=false&init=false&interface=com.itbz.shopping_common.service.MessageService&metadata-type=remote&methods=sendMessage&pid=2912&qos.enable=false&register.ip=192.168.119.1&release=2.7.8&remote.application=shopping_message_service&side=consumer&sticky=false&timestamp=1689070199503, cause: org.apache.dubbo.remoting.TimeoutException: Waiting server-side response timeout by scan timer. start time: 2023-07-11 18:12:40.651, end time: 2023-07-11 18:12:41.662, client elapsed: 1 ms, server elapsed: 1010 ms, timeout: 1000 ms, request: Request [id=2, version=2.0.2, twoway=true, event=false, broken=false, data=RpcInvocation [methodName=sendMessage, parameterTypes=[class java.lang.String, class java.lang.String], arguments=[185909224615, 9527], attachments={path=com.itbz.shopping_common.service.MessageService, remote.application=shopping_user_customer_api, interface=com.itbz.shopping_common.service.MessageService, version=0.0.0}]], channel: /192.168.66.10:63073 -> /192.168.66.10:20880
最新发布
07-12

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值