mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Android Embedding PR26: Offer an async version of FlutterMain's ensure initialization complete. (#8465)
This commit is contained in:
parent
a930ca8935
commit
dbcfc504cc
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user