未验证 提交 dbcfc504 编写于 作者: M Matt Carroll 提交者: GitHub

Android Embedding PR26: Offer an async version of FlutterMain's ensure...

Android Embedding PR26: Offer an async version of FlutterMain's ensure initialization complete. (#8465)
上级 a930ca89
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册