I’m writing a plugin for capacitor running on Android. Plugin generally works, but it is getting an error message that I would like to understand/remove.
The plugin is performing an authentication session with the user, so the plugin has asynchronous operations and launches a new Intent for this.
When the activity call back is run, it issues the “call.resolve()” to complete the plugin and to return to the ionic app.
However when the app is subsequently put in the background some time later, this error message is shown:
2024-02-28 10:49:47.605 24307-24307 Capacitor/AppPlugin com.myitops.asiapp V Notifying listeners for event pause
2024-02-28 10:49:47.605 24307-24307 Capacitor/AppPlugin com.myitops.asiapp D No listeners found for event pause
2024-02-28 10:49:47.605 24307-24307 Capacitor com.myitops.asiapp D App paused
2024-02-28 10:49:47.990 24307-24307 Capacitor/AppPlugin com.myitops.asiapp D Firing change: false
2024-02-28 10:49:47.991 24307-24307 Capacitor/AppPlugin com.myitops.asiapp V Notifying listeners for event appStateChange
2024-02-28 10:49:47.992 24307-24307 Capacitor/AppPlugin com.myitops.asiapp D No listeners found for event appStateChange
2024-02-28 10:49:47.995 24307-24307 Capacitor com.myitops.asiapp D App stopped
2024-02-28 10:49:48.002 24307-24307 Capacitor com.myitops.asiapp D Saving instance state!
2024-02-28 10:49:48.004 24307-24307 Capacitor com.myitops.asiapp E Couldn't save last ISSAuth's Plugin authenticate call
To me this looks like the plugin mechanism has failed to terminate the call to the “authenticate” plugin and left the “call” object in a confused state - the plugin has finished, so there is no need to be saving the “call” object for it.
The general structure of my plugin is:
@PluginMethod()
public void authenticate(PluginCall call) {
... do stuff
... setup Intent for performing the auth...
Intent authIntent = this.authService.getAuthorizationRequestIntent(authRequest);
startActivityForResult(call, authIntent, "authCallback");
}
@ActivityCallback
void authCallback(PluginCall call, ActivityResult result) {
... do stuff
... get access tokens using an asynchronous callback...
this.authservice.performTokenRequest(
....,
(resp1, ex1) -> {. // call back function
if (resp1 != null) {
JSObject ret = new JSObject();
ret.put("accessToken", resp1.accessToken);
ret.put("refreshToken", resp1.refreshToken);
this.refreshToken = resp1.refreshToken;
call.resolve(ret);
} else {
call.reject("Token request failed!");
}
});
As I said, it all seems to work, it’s just I don’t like that error message, it looks as though something is wrong somewhere…