Directly open a form when the Start Survey button is clicked

1. What is the problem? Be very detailed.
The start survey button opens an activity with a list of all the forms available. On clicking on any of the forms, the position of the form in the ListView and its ID are retrieved. This ID is then appended to a URL which is used to specify which form has been clicked on.
I have only one form in my server and need that on clicking the start survey button, this single form is opened directly, without showing the FormChooserList activity.

2. What app or server are you using and on what device and operating system? Include version numbers.

3. What you have you tried to fix the problem?
In the onClickListener of the "start survey" button, instead of calling an intent to FormChooserList Activity I copy pasted the following code:

 Uri formUri = ContentUris.withAppendedId(FormsProviderAPI.FormsColumns.CONTENT_URI, 1);
        String action = getIntent().getAction();
        if (Intent.ACTION_PICK.equals(action)) {
            // caller is waiting on a picked form
            setResult(RESULT_OK, new Intent().setData(formUri));
        } else {
            // caller wants to view/edit a form, so launch formentryactivity
            Intent intent = new Intent(Intent.ACTION_EDIT, formUri);
            intent.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
            startActivity(intent);
        }
        finish();

As can bee seen in the first line, I simply put the number 1 instead of a variable that would have saved ID of the form thinking that if only one form is uploaded on the server, its ID would be 1.
Uri formUri = ContentUris.withAppendedId(FormsProviderAPI.FormsColumns.CONTENT_URI, 1);
However, the said ID keeps changing from device to device. It also changes when the old form is deleted and a new one is replaced.
I cannot figure out any logic as to how these forms are being assigned these IDs.

4. What steps can we take to reproduce the problem?
It would be great if anyone could tell me any logic of how the IDs are generated or any other way to achieve what i want.

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.
Whenever the ID of my form on the server changes, while I have coded it to be a particular number, I get the error: BAD URI.

I hope i managed to explain my issue.

You can just get all forms https://github.com/opendatakit/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/dao/FormsDao.java#L232 using https://github.com/opendatakit/collect/blob/master/collect_app/src/main/java/org/odk/collect/android/dao/FormsDao.java#L38

since you have just one form you can read the first one and use its id.

Thank you for your reply.
I am sorry, but I couldn't understand how, could you please elaborate a bit? :sweat_smile:

                    List<Form> forms = formsDao.getFormsFromCursor(formsDao.getFormsCursor());
                    if (!forms.isEmpty()) {
                        Uri formUri = ContentUris.withAppendedId(FormsProviderAPI.FormsColumns.CONTENT_URI, forms.get(0).getId());

                        Intent intent = new Intent(Intent.ACTION_EDIT, formUri);
                        intent.putExtra(ApplicationConstants.BundleKeys.FORM_MODE, ApplicationConstants.FormModes.EDIT_SAVED);
                        startActivity(intent);
                    }
2 Likes