How to move another activity for changing control mode from manual to autonomous on same device in Android

Product: bebop
Product version: [X.X.X]
SDK version: [3.11.0]
Use of libARController: [YES] (Only for ARSDK)
SDK platform: [Android]
Reproductible with the official app: [Not tried]

Hello

I am developing app using your sample code(https://github.com/Parrot-Developers/Samples) for autonomous flight
In this app, I am trying to change flight mode by creating new activity after starting ‘BebopActivity’ when I click button or something.
However, when I clicked button, the new one couldn’t be created and occurred error like below. And my code is also below
I think, it is problems when controller reconnects to drone that already connected in 'BebopActivity’
Please give some advises or hints whoever knows how to solve this problem or have idea.

Thank you


In BebopActivity.java

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bebop);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

Toolbar myToolbar = (Toolbar) findViewById(R.id.configuration_toolbar);
setSupportActionBar(myToolbar);

initIHM();

Intent intent = getIntent();
service = intent.getParcelableExtra(DeviceListActivity.EXTRA_DEVICE_SERVICE);
mBebopDrone = new BebopDrone(this, service);
mBebopDrone.addListener(mBebopListener);

}

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

// show a loading view while the bebop drone is connecting
if ((mBebopDrone != null) && !(ARCONTROLLER_DEVICE_STATE_ENUM.ARCONTROLLER_DEVICE_STATE_RUNNING.equals(mBebopDrone.getConnectionState())))
{
    mConnectionProgressDialog = new ProgressDialog(this, R.style.AppCompatAlertDialogStyle);
    mConnectionProgressDialog.setIndeterminate(true);
    mConnectionProgressDialog.setMessage("Connecting ...");
    mConnectionProgressDialog.setCancelable(false);
    mConnectionProgressDialog.show();

    // if the connection to the Bebop fails, finish the activity
    if (!mBebopDrone.connect())
    {
        finish();
    }
}

}

@Override
public void onBackPressed()
{
if (mBebopDrone != null)
{
mConnectionProgressDialog = new ProgressDialog(this, R.style.AppCompatAlertDialogStyle);
mConnectionProgressDialog.setIndeterminate(true);
mConnectionProgressDialog.setMessage(“Disconnecting …”);
mConnectionProgressDialog.setCancelable(false);
mConnectionProgressDialog.show();

    if (!mBebopDrone.disconnect())
    {
        finish();
    }
}

}

@Override
public void onDestroy()
{
mBebopDrone.dispose();
super.onDestroy();
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
Intent intent;
// Intent intent = null;
switch (item.getItemId())
{
case R.id.AutoFlight:
intent = new Intent(this, AutoFlightActivity.class);
if (intent != null)
{
intent.putExtra(EXTRA_DEVICE_SERVICE, service);
startActivity(intent);
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}

In AutoFlightActivity.java

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auto_flight);

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

initIHM();

Intent intent = getIntent();
ARDiscoveryDeviceService service = intent.getParcelableExtra(BebopActivity.EXTRA_DEVICE_SERVICE);
mBebopDroneAuto = new BebopDroneAuto(this, service);
mBebopDroneAuto.addListener(mBebopListener);

}

@Override
protected void onStart()
{
try
{
super.onStart();
// show a loading view while the bebop drone is connecting
if ((mBebopDroneAuto != null) && !(ARCONTROLLER_DEVICE_STATE_ENUM.ARCONTROLLER_DEVICE_STATE_RUNNING.equals(mBebopDroneAuto.getConnectionState())))
{
mConnectionProgressDialog = new ProgressDialog(this, R.style.AppCompatAlertDialogStyle);
mConnectionProgressDialog.setIndeterminate(true);
mConnectionProgressDialog.setMessage(“Connecting …”);
mConnectionProgressDialog.setCancelable(false);
mConnectionProgressDialog.show();

        // if the connection to the Bebop fails, finish the activity
        if (!mBebopDroneAuto.connect())
        {
            finish();
        }
    }
}
catch (Exception e)
{
    Log.e(TAG, "Exception", e);
}

}

@Override
public void onBackPressed()
{
if (mBebopDroneAuto != null)
{
mConnectionProgressDialog = new ProgressDialog(this, R.style.AppCompatAlertDialogStyle);
mConnectionProgressDialog.setIndeterminate(true);
mConnectionProgressDialog.setMessage(“Disconnecting …”);
mConnectionProgressDialog.setCancelable(false);
mConnectionProgressDialog.show();

    if (!mBebopDroneAuto.disconnect())
    {
        finish();
    }
}

}


In BebopDroneAuto.java

public BebopDroneAuto(Context context, @NonNull ARDiscoveryDeviceService deviceService)
{
mListeners = new ArrayList<>();

// needed because some callbacks will be called on the main thread
mHandler = new Handler(context.getMainLooper());

mState = ARCONTROLLER_DEVICE_STATE_ENUM.ARCONTROLLER_DEVICE_STATE_STOPPED;

// if the product type of the deviceService match with the types supported
ARDISCOVERY_PRODUCT_ENUM productType = ARDiscoveryService.getProductFromProductID(deviceService.getProductID());
ARDISCOVERY_PRODUCT_FAMILY_ENUM family = ARDiscoveryService.getProductFamily(productType);
if (ARDISCOVERY_PRODUCT_FAMILY_ENUM.ARDISCOVERY_PRODUCT_FAMILY_ARDRONE.equals(family))
{
    ARDiscoveryDevice discoveryDevice = createDiscoveryDevice(deviceService, productType);
    if (discoveryDevice != null)
    {
        mDeviceController = createDeviceController(discoveryDevice);
        discoveryDevice.dispose();
    }
    try
    {
        // TODO : 중복으로 connect 필요?
        String productIP = ((ARDiscoveryDeviceNetService) (deviceService.getDevice())).getIp();

        ARUtilsManager ftpListManager = new ARUtilsManager();
        ARUtilsManager ftpQueueManager = new ARUtilsManager();

        ftpListManager.initWifiFtp(productIP, DEVICE_PORT, ARUtilsManager.FTP_ANONYMOUS, "");
        ftpQueueManager.initWifiFtp(productIP, DEVICE_PORT, ARUtilsManager.FTP_ANONYMOUS, "");

        // mSDCardModule = new SDCardModule(ftpListManager, ftpQueueManager);
        // mSDCardModule.addListener(mSDCardModuleListener);
    }
    catch (ARUtilsException e)
    {
        Log.e(TAG, "Exception", e);
    }

}
else
{
    Log.e(TAG, "DeviceService type is not supported by BebopDrone");
}

}


Error Message

02-10 13:09:31.422 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:31:433 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:31.422 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:31:433 | ARNETWORK_Sender_ProcessBufferToSend:421 - [0x7f5cebe880] Will retry sending data of buffer 11
02-10 13:09:31.922 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:31:934 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:31.922 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:31:934 | ARNETWORK_Sender_ProcessBufferToSend:421 - [0x7f5cebe880] Will retry sending data of buffer 11
02-10 13:09:32.422 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:32:435 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:32.422 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:32:435 | ARNETWORK_Sender_ProcessBufferToSend:421 - [0x7f5cebe880] Will retry sending data of buffer 11
02-10 13:09:32.922 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:32:936 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:33.422 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:33:436 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:33.422 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:33:437 | ARNETWORK_Sender_ProcessBufferToSend:421 - [0x7f5cebe880] Will retry sending data of buffer 11
02-10 13:09:33.922 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:33:937 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:33.922 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:33:937 | ARNETWORK_Sender_ProcessBufferToSend:421 - [0x7f5cebe880] Will retry sending data of buffer 11
02-10 13:09:34.422 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:34:438 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:34.422 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:34:438 | ARNETWORK_Sender_ProcessBufferToSend:421 - [0x7f5cebe880] Will retry sending data of buffer 11
02-10 13:09:34.922 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:34:938 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:35.432 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:35:439 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:35.432 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:35:439 | ARNETWORK_Sender_ProcessBufferToSend:421 - [0x7f5cebe880] Will retry sending data of buffer 11
02-10 13:09:35.932 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:35:940 | ARNETWORK_Sender_ProcessBufferToSend:405 - [0x7f5cebe880] Timeout waiting for ack in buffer 11
02-10 13:09:35.932 14931-18568/com.example.pelennor.dronetest E/ARNETWORK_Sender: 13:09:35:940 | ARNETWORK_Sender_ProcessBufferToSend:421 - [0x7f5cebe880] Will retry sending data of buffer 11
02-10 13:09:36.902 14931-18553/com.example.pelennor.dronetest E/ARCONTROLLER_Device: 13:09:36:917 | ARCONTROLLER_Device_StartRun:4995 - Start fail error :start canceled
02-10 13:09:37.012 14931-14931/com.example.pelennor.dronetest E/ViewRootImpl: sendUserActionEvent() mView == null

Hi,

To use one deviceController and keep it connected while going from an activity to another, you should put the device controller in an object that is not destroyed during the activity change.
The best place should be in a Service.

Best regards
Djavan

1 Like