1

Am trying to bind one service as an isolated process in my react native Android app

           <service
            android:name="com.xx.xx.services.IsolatedService"
            android:enabled="true"
            android:isolatedProcess="false"
            android:process=":service" />

But if enabled the service as an isolated process then service is not binding else it's working fine. I have tried in a simple native android app and its binding without any issue.

public class MainActivity extends ReactActivity {

    private AIDLInterface serviceBinder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this, R.style.SplashScreenTheme);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onStart() {
        super.onStart();

         Intent intent = new Intent(this, IsolatedService.class);
         this.getApplicationContext().bindService(intent, mIsolatedConnection, BIND_AUTO_CREATE);

    }
    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "xcvxcv";
    }
    
    private ServiceConnection mIsolatedConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            serviceBinder = AIDLInterface.Stub.asInterface(iBinder);
            // Console.log("mIsolatedConnection");
        }
        @Override
        public void onServiceDisconnected(ComponentName componentName) {
           // Console.log("onServiceDisconnected");
        }
    };
}

its not giving onServiceDisconnected /onServiceConnected or any exception.

but the same is binding to the service if I update the isolatedProcess as false

1
  • I have the same issue, any updates to fix this issue? Commented Apr 27, 2021 at 2:54

1 Answer 1

1

I have fixed this issue, just adding try-catch to SoLoader.init and initializeFlipper in application class

  @Override
  public void onCreate() {
    super.onCreate();
    try{
        // isolated process is unable to run these code
        // use try catch to be able running isolated process
        SoLoader.init(this, /* native exopackage */ false);
        initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
    } catch (Exception e){
        e.printStackTrace();
    }

  }

Isolated process will run the application class, if onServiceConnected method isn't called, you have to check your application class. Some code doesn't work properly in an isolated process. So you have to add a try-catch to fix this issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.