Android Question Sending emails with Gmail REST API from another Activity causes a refresh token problem

Andris

Active Member
Licensed User
Longtime User
The first token parameter in GoogleOauth2 sets the target module. This is the module that will receive all events. If you want to use it from multiple activities then add a service (or use the Starter service) and from the service delegate the event to whichever activity you like.

The tutorial demo in the thread referenced above works perfectly for me as is. However, I want to handle emailing from a different activity called Email, so I've set the first parameter in GoogleOAuth2 to Email and moved subroutine Send to the Email activity. I can send emails fine after the first install, while the authentication token is valid. However, if I compile again a while later, after the token has expired, I get these log messages:
B4X:
Getting access token from refresh token...
Object context is paused. Ignoring CallSubDelayed: JobDone
This doesn't happen if Sub Send is in Main instead of Email. It seems that an event is being raised by GoogleOAuth2 in Main, instead of in Email, where I would expect it to be because I set Email as the target. Does anyone have any input on this?
 

Andris

Active Member
Licensed User
Longtime User
It will be simpler to use the starter service for this. You can then start the target activity or do whatever you need to do. It will not be paused (there is a small exception here related to Android 8+ devices. It will be taken care automatically in the next version of B4A).

Thanks Erel. Using Starter seems to work fine. I've attached a zip file that modifies the original Tutorial demo to show a second Emailer activity and the additions to Starter. Add the ClientID and the recipient email address in Starter. Hopefully it will help others who currently have the same problem.
 

Attachments

  • GmailFromActivity.zip
    61.4 KB · Views: 365
Upvote 0
Top