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

APP中添加了一个独立进程 Service,按返回关闭APP主界面后,再打开无法连接Service发出的事件 #33

Open
sxlvalue opened this issue May 3, 2017 · 2 comments
Labels

Comments

@sxlvalue
Copy link

sxlvalue commented May 3, 2017

APP中添加了一个 Service,并在mainfest中配置service为android:process=":TestService"。从service中POST事件,主界面可以正常收到消息。按返回键退出主界面后,再次打开无法收到消息。
想了一下,可能init是在主APP的application中初始化的不行,尝试在application中初始化,没有效果。
看init源码如下:
public void init(Context context) {
mContext = context.getApplicationContext();
mMainProcess = isMainProcess(context.getApplicationContext());
if (mMainProcess) {
Hermes.init(context);
Hermes.register(MainService.class);
mMainApis = MainService.getInstance();
} else {
mState = STATE_CONNECTING;
Hermes.setHermesListener(new HermesListener());
Hermes.connect(context, Service.class);
Hermes.register(SubService.class);
}
}
在Service中执行init时,mMmainProcess为false,也就是永远不能从服务来执行初始化,可是现实确是往往service的生命周期都比前台进程要长。
作者能不能指点一下,如何解决这个问题。

@Xiaofei-it
Copy link
Owner

Xiaofei-it commented May 5, 2017

正常手机主进程存活时间最长,但确实有很多国产手机在主进程崩溃之后子进程还活着。

目前没有考虑你说的那种case。建议Hermes的服务端放在主进程,并且对主进程做保活。如果还坚持放在子进程,可以考虑Hermes库,这个库对进程没有限制。

@siyehua
Copy link

siyehua commented Apr 26, 2020

我也遇到这个问题,解决方法是凡是通信的进程都要持有对应的 Binder。当 A 进程启动的时候,通过启动 B,C,D 这三个进程的服务,拿到对应的 binder,进行 aidl 通信。
如果 A 进程挂掉了,启动的时候重新绑定一次即可

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

No branches or pull requests

3 participants