Android Setup Library - returns to my app after login/create

Hi there. I integrated the Android Setup Library (compile ‘io.particle:devicesetup:0.3.6’) into my app, and can start it up properly. I have “Organization” set to True, and have my org-slug and product-slug set.

The problem is that whenever I either log in or register a new customer the setup app immediately starts a new instance of my main activity (instead of showing its “Let’s get Started” activity). I don’t see anything in the logs to show what might have happened.

Thanks,
Dan

I’ve got two more issues in addition to the one above:

  1. I set up a DeviceSetupCompleteReceiver as described in the docs. But it is never called – whether the setup completes as a success or failure.

  2. When testing the setup on a Particle that has already been claimed by a customer, the setup gets stuck just after it sets the device’s wifi credentials and reclaims it. The device is actually done setting up – breathing cyan, dashboard says online and owned by the correct customer, etc. – but the setup app hangs at attempting to verify the connection. The android log shows that it’s trying to connect to 192.168.0.1 for some reason. That’s the softAP address, right?

Who is currently in charge of the android setup library app? I need to nail down these issues so that I can release my product.

Thanks,
Dan

I'd say @ido might be a good bet

@dperrigan what version of the setup lib are you using?

Also, when you register the DeviceSetupCompleteReceiver, are you maintaining a reference to it? It’s possible that it’s being garbage collected.

Hi @jensck. Thanks for the reply.

It’s 0.3.6.

As to the DeviceSetupCompleteReceiver, here are some code snippets to show what I’m doing:

public class MainRCActivity extends AppCompatActivity {

    private static ParticleDeviceSetupLibrary.DeviceSetupCompleteReceiver receiver;

And later…

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rc_main);
...
        ParticleDeviceSetupLibrary.init(this.getApplicationContext(), MainRCActivity.class);

        receiver = new ParticleDeviceSetupLibrary.DeviceSetupCompleteReceiver() {

            @Override
            public void onSetupSuccess(@NonNull String configuredDeviceId) {
                Toaster.s(MainRCActivity.this, "Hooray, you set up device " + configuredDeviceId);

                doDeviceRename(configuredDeviceId);
            }

            @Override
            public void onSetupFailure() {
                Toaster.s(MainRCActivity.this, "Sorry, device setup failed.  (sad trombone)");
            }
        };

Then later if a device can’t be found, a dialog asking whether to set one up:

public class DoSetupFragment extends DialogFragment {
        @Override
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            // Use the Builder class for convenient dialog construction
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage("Unable to find a valid Device.\nDo you want to set up a new one now?")
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            DoSetup();
                        }
                    })
                    .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // User cancelled the dialog
                        }
                    });
            // Create the AlertDialog object and return it
            return builder.create();
        }
    }

    private void DoSetup(){
        receiver.register(MainRCActivity.this);
        ParticleDeviceSetupLibrary.startDeviceSetup(MainRCActivity.this);
        receiver.unregister(MainRCActivity.this);
    }

Thanks!
Dan

Ah, I see the problem. The point of having a callback receiver like that is that the setup process isn’t a blocking call, it’s async. Right now, you are unregistering immediately after calling the asynchronous startDeviceSetup() method, so that by the time setup is complete, the receiver is unregistered. :slight_smile:

Thanks. That’s what I get for copying and pasting the example code from the reference section blindly. Now I see the caveat of “…and when setup is complete…” before the unregister command.

Any ideas on my other problem? (copied below)

  1. The problem is that whenever I either log in or register a new customer
    the setup app immediately starts a new instance of my main activity
    (instead of showing its “Let’s get Started” activity). I don’t see
    anything in the logs to show what might have happened.

Thanks again for your help,
Dan

Does that still happen if you install the app fresh, or is it only after you’ve logged out as one user and back in with another user?