How to unregister app with DJISDKManager and SDKManagerCallback correctly with Mobile-SDK-Android?

问题: Environment gradle implementation 'com.dji:dji-sdk:4.6' compileOnly 'com.dji:dji-sdk-provided:4.6' Application class (new Helper setup) public class DJISampleAppli...

问题:

Environment

gradle

implementation 'com.dji:dji-sdk:4.6'
compileOnly 'com.dji:dji-sdk-provided:4.6'

Application class (new Helper setup)

public class DJISampleApplication extends Application {

    @Override protected void attachBaseContext(Context paramContext) {
        super.attachBaseContext(paramContext);
        Helper.install(this);
    }

    ...

}

MainActivity (start SDK registration)

AsyncTask.execute(() -> DJISDKManager.getInstance()
    .registerApp(getActivity(), new DJISDKManager.SDKManagerCallback() {

        @Override public void onRegister(DJIError djiError) {
            if (djiError == DJISDKError.REGISTRATION_SUCCESS) {
                DJISDKManager.getInstance().startConnectionToProduct();
            }
        }

        @Override public void onProductDisconnect() {}
        @Override public void onProductConnect(BaseProduct baseProduct) {}
        @Override public void onComponentChange(BaseProduct.ComponentKey componentKey, BaseComponent oldComponent, BaseComponent newComponent) {}

    })
);

Problem

After calling 'registerApp' from the DJISDKManager instance, everything works as expected. If you back out of the application, the DJISDKManager or other DJI related classes, do not respect the Activity/Fragment lifecycles.

The first (and more obvious) issues that I noticed is that DJISDKManager keeps polling for a location. The system bar location icon never goes away, which is telling me that something is still running from the DJI SDK setup. I am not even sure why it is polling for a location but I assume it has something to do with registering the app.

location icon

Taking a deeper look using the Android Profiler tool in Android Studio, I can confirm that DJI related threads are continuously running. This happens until the Android OS (which I am mainly testing on v8.1.0 using a Pixel XL). Below is a screenshot that shows SwUdpService (located in dji.midware.sockets.P3) that is always running. You will also notice DjiExecutor, which happens every min or so. Keep in mind, this is all happening while the app is in the background. If you would force close the app, all of this goes away including the location icon.

DJI SDK in the background showing in Android Profiler


Extra Info

I have tried a bunch of different tests but mainly have been testing DJI-SDK 4.5.1 and 4.6. Going back to an earlier SDK is not an option due to the new drone support. Please note, I kept my code very minimal in my tests and in this post so I could exactly pinpoint what code triggers the background threads that never stop.

DJISDKManager provides a few methods of interest but does not work as expected.

DJISDKManager.getInstance().destroy();

A destroy method, which in every scenario that I tested just crashes the app. It seems that it kills all of the SDK references but then some code still trying to run cannot find classes initially setup from the Helper.class throws exceptions and crashes the app.

DJISDKManager.getInstance().stopConnectionToProduct();

The stopConnectionToProduct does not do what I need. I am pretty sure this is more to stop receiving callbacks for product changes but in my testing did not really change any behavior. In fact, startConnectionToProduct does not seem to be needed anymore. Maybe these are both old methods that should be deprecated?

As we all know, the DJI SDK is very limited for obvious reasons. It seems to me that there is not 'unregisterApp' for the SDK and no public way to correctly control these DJI threads and respect the Android lifecycle. I did notice that the Android SDK sample that DJI provides behaves the same way. I tested both 4.5.1 and 4.6 branches on their repo located here: https://github.com/dji-sdk/Mobile-SDK-Android

If you test the DJI GO app, they correctly handle the Android lifecycle and from what I tell there are no threads continuously running in the background.


What I Need

I am quite new to DJI SDK development but have been developing Android applications for a long time. I know the DJI SDK has changed a lot on how you set things up, control different managers, etc. I mainly want to confirm I am not overlooking something. If I am indeed not overlooking the obvious, does anyone have a solution?

It would be awesome if we had more control over how our apps initialize the DJISDKManager, register or app, and handle callbacks/listeners. Right now its setup for a "hail mary" register function that has one callback that does too much. The fact that DJISDKManager is already a static instance and has no public control methods, it seems impossible to efficiently use the SDK.

I would love to be able to properly setup DJISDKManager as a lifecycle-aware component. I have even done some testing with manager helper class that implements LifecycleObserver, but lacking any way to stop DJI's services/threads/etc, it's pointless to use. In this LifecycleObserver class, I have even tried setting the callback to null onPause and recreate a new callback/register app onResume. This changes no behavior.

Thanks for reading :)


回答1:

Can you send this issue to dev@dji.com - we'd like to research this further for you

  • 发表于 2018-07-13 00:25
  • 阅读 ( 478 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除