Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

启动第2个app进程的时候发现service0无法绑上 #14

Open
ivanyang1984 opened this issue Oct 23, 2017 · 2 comments
Open

启动第2个app进程的时候发现service0无法绑上 #14

ivanyang1984 opened this issue Oct 23, 2017 · 2 comments

Comments

@ivanyang1984
Copy link

之前service0 启动后 验证 service 已经起~
public static boolean isServiceExisted(Context context, String className) {
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(Integer.MAX_VALUE);
if(!(serviceList.size() > 0)) {
return false;
}
for(int i = 0; i < serviceList.size(); i++) {
ActivityManager.RunningServiceInfo serviceInfo = serviceList.get(i);
ComponentName serviceName = serviceInfo.service;
if(serviceName.getClassName().equals(className)) {
return true;
}
}
return false;
}

但是到了 B APP进程里 总是绑不上~

@ivanyang1984
Copy link
Author

解决了
public class MyService extends HermesService {

private IBinder mBinder = new IHermesService.Stub(){
    @Override
    public Reply send(Mail mail) throws RemoteException {
        return null;
    }

    @Override
    public void register(IHermesServiceCallback callback, int pid) throws RemoteException {

    }

    @Override
    public void gc(List<Long> timeStamps) throws RemoteException {

    }
};

@Override
public IBinder onBind(Intent intent) {
    return mBinder;
}

}

@ivanyang1984
Copy link
Author

感觉必须要自己写一个Service 通过 隐式 action的方式调用 才能成功。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant