ActivityStarter Extension by pepemont, updated by Sergio

I rebuilt the ActivityStarter module as an extension, introducing the changes that pepemont suggested, and it’s working now without any errors. Its called XXActivityStarter and I leave it here just in case it could be of help to anyone, but I want to clarify that I did not test the whole extension features (I tested just the part that was causing the issue, which is inserting a calendar event).

Best regards and thank you very much for your help.


EDIT (by Taifun): the original Activity Starter Extension by pepemont, which additionally is able to pass boolean and long values can be found here, which offered the following help/documentation:

I was able to modify Activity Starter (as a new extension call Xactivity Starter) to allow setting beginTime and endTime of an event into Android calendar.

The change to code source was trivial :

if (key.length() != 0 && value.length() != 0) { 
  Log.i("ActivityStarter", "Adding extra (pairs), key = " + key + " value = " + value);

  if (key.startsWith("B.")) { 
    key = key.substring(2); 
    intent.putExtra(key, Byte.parseByte(value)); 
  } else if (key.startsWith("l.")) { 
    key = key.substring(2); 
    intent.putExtra(key, Long.parseLong(value));
  } else {
    intent.putExtra(key, value); 
  } 
  return intent; 
}

`

How to use the extension
Any key starting with "B." (an upper case B followed by a dot) or "l." (a lower case L followed by a dot) will be passed as boolean or long respectively.

Example of use:

3 Likes

Hi Taifun, thank you for moving the thread to the Extensions category.
The original code from pepemont had to be slightly modified because I think the ActivityStarter Module has changed a little since pepemont created the first ActivityStarter extension. The following new code is mostly the same as the code portion that you posted:

if (extraKey.length() != 0 && extraValue.length() != 0) {
            Log.i(LOG_TAG, "Adding extra, key = " + extraKey + " value = " + extraValue); 

        //==========================================================
        // The following code was added to the original ActivityStarter code
        // It was created by user "pepemont" and the idea is that any key starting
        // with "B." (an upper case B followed by a dot) or "l." (a lower case L
        // followed by a dot) will be passed as boolean or long respectively.
        //==========================================================
           
            if (extraKey.startsWith("B.")) {
                extraKey = extraKey.substring(2);
                intent.putExtra(extraKey, Byte.parseByte(extraValue));
            } else if (extraKey.startsWith("l.")) {
                extraKey = extraKey.substring(2);
                intent.putExtra(extraKey, Long.parseLong(extraValue));
            } else intent.putExtra(extraKey, extraValue);

            //========================================================== 
            // End of addition. The original code just had the following line instead of
            // the conditional statemets above:
            //
            // intent.putExtra(extraKey, extraValue);
            //========================================================== 

        }

        // If the extra value is a string, put it to the intent. If the extra value is a list
        // of strings, convert it to a java list and put that to the intent.

        for (Object extra : extras.toArray()) {
            YailList castExtra = (YailList) extra;
            String key = castExtra.getString(0);
            Object value = castExtra.getObject(1);
            Log.i(LOG_TAG, "Adding extra, key = " + key + " value = " + value);
            if ((key.length() != 0)) {
                if (value instanceof YailList) {
                    Log.i(LOG_TAG, "Adding extra list, key = " + key + " value = " + value);
                    intent.putExtra(key, ((YailList) value).toStringArray());
                } else {
                    String stringValue = castExtra.getString(1);
                    Log.i(LOG_TAG, "Adding extra string, key = " + key + " value = " + stringValue);

                    //========================================================== 
                    // The following code was added to the original ActivityStarter code
                    // It was created by user "pepemont", and the idea is that any key starting
                    // with "B." (an upper case B followed by a dot) or "l." (a lower case L
                    // followed by a dot) will be passed as boolean or long respectively.
                    //========================================================== 

                    if (key.startsWith("B.")) {
                        key = key.substring(2);
                        intent.putExtra(key, Byte.parseByte(stringValue));
                    } else if (key.startsWith("l.")) {
                        key = key.substring(2);
                        intent.putExtra(key, Long.parseLong(stringValue));
                    } else intent.putExtra(key, stringValue);

                   //========================================================== 
                   // End of addition. The original code just had the following line instead of
                   // the conditional statemets above:
                   //
                   // intent.putExtra(key, stringValue);
                   //========================================================== 

                }
            }
            ;
        }

ActivityStarter allows users to pass parameters as a single key/value pair using the "Extra Key" and "Extra Value" properties, or as a set of key/value pairs passed in a list, by using the "Extras" property.
As you can see above, I added the code from pepemont to both the "Extra Key / Extra Value" properties as well as to the "Extras" property (previous ActivityStarter extension from pepemont did not include the correction to the Extra Key/Extra Value properties).

Hope this helps.

Best regards,

Sergio

2 Likes

Thank you for the additional information...

You also might want to upload the Java file into this thread, which might make it easier next time for someone else to make any improvements for future Android versions...

In case you are not allowed to upload a file with extension .java, just rename it to .txt before uploading... Thank you

Taifun

2 Likes

The following is the Java file for the extension (it was renamed to XXActivityStarter.txt to be able to be uploaded)
XXActivityStarter.txt (19.0 KB)

Best regards,

Sergio

2 Likes

I think the required feature was already available.

1 Like

Thanks vknow360. Indeed there was an ActivityStarter extension that fixed the issue but introduced a RunTime Error. Just re-compiling the extension solved the RunTime Error and everything is working perfect now.
By the way I downloaded the IntentStarter extension that you mentioned and tried in my app, and it's throwing the following error:

Error 601: No corresponding activity was found

I don´t have any errors using my new extension, so I think I will go with it.

Thanks anyway and best regards,

Sergio