Android Embedding PR26: Offer an async version of FlutterMain's ensure initialization complete. (#8465)

This commit is contained in:
Matt Carroll 2019-04-08 14:46:41 -07:00 committed by GitHub
parent a930ca8935
commit dbcfc504cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,7 @@ import android.content.res.AssetManager;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.util.Log;
@ -242,6 +243,41 @@ public class FlutterMain {
}
}
/**
* Same as {@link #ensureInitializationComplete(Context, String[])} but waiting on a background
* thread, then invoking {@code callback} on the {@code callbackHandler}.
*/
public static void ensureInitializationCompleteAsync(
Context applicationContext,
String[] args,
Handler callbackHandler,
Runnable callback
) {
if (Looper.myLooper() != Looper.getMainLooper()) {
throw new IllegalStateException("ensureInitializationComplete must be called on the main thread");
}
if (sSettings == null) {
throw new IllegalStateException("ensureInitializationComplete must be called after startInitialization");
}
if (sInitialized) {
return;
}
new Thread(new Runnable() {
@Override
public void run() {
sResourceExtractor.waitForCompletion();
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
ensureInitializationComplete(applicationContext.getApplicationContext(), args);
callbackHandler.post(callback);
}
});
}
}).start();
}
private static native void nativeInit(Context context, String[] args, String bundlePath, String appStoragePath, String engineCachesPath);
private static native void nativeRecordStartTimestamp(long initTimeMillis);