GeezerVison is showing github.com — Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time · Issue #603 · GoogleCloudPlatform/java-docs-samples
Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time #603DescriptionIn my Main Activity, I initialize the Translate variable. If you look at the logs: I track when the initialization starts and when it finishes. Most of the time it initializes quick. But 1/5 times it takes up to 30 seconds to 3 minutes (UNACCEPTABLE).
AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {
@Override
public void onPostExecute (Void aVoid) {
Log.i("APP", "finished");
}
@Override
protected Void doInBackground(Void... voids) {
Log.i("APP", "start");
Translate translate = TranslateOptions.newBuilder().setApiKey("XXXXX-ZZZZZ").build().getService();
return null;
}
};
asyncTask.execute();
I also have the latest versions in gradle:
compile ('com.google.cloud:google-cloud-translate:0.11.0-alpha')
compile ('com.google.apis:google-api-services-translate:v2-rev49-1.22.0')
Activitychanged the title [-]translate2 = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time[/-] [+]Translate translate = TranslateOptions.newBuilder().setApiKey(MY_API_KEY).build().getService(); Sometimes Takes Very Long time[/+] on Apr 8, 2017lesv commented on Apr 22, 2017 Totally agree with you. 3 minutes is unacceptable. Shouldn't you create the Translate object only once at startup?
Where are you running this?
I'll try to get you an answer, but this really should be a question for StackOverflow
NOTE - You might wish to invalidate your ApiKey, and just change to xxxx when posting in the future. lesv commented on Apr 22, 2017 Ah, found your SO Question and that your running on Android, so my comment is moot, though you might still wish to run a cloud service that initializates Translate and just request from that. lesv commented on Apr 22, 2017 I'm sorry to say that if you look at the bottom of google-cloud-java, you note that "Android is not supported" for these libraries currently. lesv commented on Apr 22, 2017 grantespo commented on Apr 22, 2017 How is it not supported on Android? I am using it in my production app right now and it translates messages good. It just takes a long time to initialize sometimes.
I am initializing it in my Application class. lesv commented on Apr 22, 2017 The engineering team hasn't had a chance to validate or optimize the library on Android so they asked that a warning be posted. I'm a bit surprised that it works at all -- there are files you might wish to change for Android such as excluding netty-borring-ssl-native and following the suggestion for TLS on Android.
You might also wish to look at these examples. But as I said, we aren't testing on Android currently, so you are on your own. My apologies.
That said, you will likely find that implementing with REST will produce a much smaller app and a much faster one.
@GoogleCloudPlatform/gcloud FYI grantespo commented on Apr 22, 2017 Will the team resume work? Is this library likely to stop working soon? Is it critical for me to transfer to REST API because I am actually happy with the performance right now. lesv commented on Apr 22, 2017 There aren't any plans to break things. (and you can stay on a working version anyway) It's just surprising that it works on Android at all.
REST might be the way to fix your 20% startup issues. (but I don't know the root cause). That's why I suggested it. Otherwise, it's really up to you. grantespo commented on Apr 23, 2017 I appreciate your replies.
My issue is never present the first time somebody opens my app. However, whenever somebody exits my app by pushing the back button, I call System.exit(0); then, after I immediately open the app again 50% of the time Translation API Initialization either delays or starts up immediately. I think the System.exit(0); plays a factor. lesv commented on Apr 23, 2017 Ah - it sounds like the shutdown threads are left in a strange state. Take a look at this which suggests System.exit() isn't the best solution.
I haven't written an Android app in several years, so I'm probably not thinking through everything. In the past, I've found this book to be invaluable.
this.finish() may be a better choice. Again, the library hasn't been tested on Android, so you are on your own here. -- hope this helps.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|