Do not pause rendering when android activity loses focus (flutter/engine#4848)
* do not pause rendering when android view loses focus
This commit is contained in:
@@ -47,10 +47,14 @@ enum AppLifecycleState {
|
|||||||
/// in the foreground inactive state. Apps transition to this state when in
|
/// in the foreground inactive state. Apps transition to this state when in
|
||||||
/// a phone call, responding to a TouchID request, when entering the app
|
/// a phone call, responding to a TouchID request, when entering the app
|
||||||
/// switcher or the control center, or when the UIViewController hosting the
|
/// switcher or the control center, or when the UIViewController hosting the
|
||||||
/// Flutter app is transitioning. Apps in this state should assume that they
|
/// Flutter app is transitioning.
|
||||||
/// may be [paused] at any time.
|
|
||||||
///
|
///
|
||||||
/// On Android, this state is currently unused.
|
/// On Android, this corresponds to an app or the Flutter host view running
|
||||||
|
/// in the foreground inactive state. Apps transition to this state when
|
||||||
|
/// another activity is focused, such as a split-screen app, a phone call,
|
||||||
|
/// a picture-in-picture app, a system dialog, or another window.
|
||||||
|
///
|
||||||
|
/// Apps in this state should assume that they may be [paused] at any time.
|
||||||
inactive,
|
inactive,
|
||||||
|
|
||||||
/// The application is not currently visible to the user, not responding to
|
/// The application is not currently visible to the user, not responding to
|
||||||
|
|||||||
@@ -100,6 +100,12 @@ public class FlutterActivity extends Activity implements FlutterView.Provider, P
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
eventDelegate.onStop();
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|||||||
@@ -218,6 +218,11 @@ public final class FlutterActivityDelegate
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStop() {
|
||||||
|
flutterView.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPostResume() {
|
public void onPostResume() {
|
||||||
if (flutterView != null) {
|
if (flutterView != null) {
|
||||||
|
|||||||
@@ -54,6 +54,11 @@ public interface FlutterActivityEvents
|
|||||||
*/
|
*/
|
||||||
void onDestroy();
|
void onDestroy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see android.app.Activity#onStop()
|
||||||
|
*/
|
||||||
|
void onStop();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when the activity has detected the user's press of the back key.
|
* Invoked when the activity has detected the user's press of the back key.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -98,6 +98,13 @@ public class FlutterFragmentActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
eventDelegate.onStop();
|
||||||
|
super.onStop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|||||||
@@ -128,7 +128,14 @@ public class FlutterNativeView implements BinaryMessenger {
|
|||||||
|
|
||||||
// Called by native to send us a platform message.
|
// Called by native to send us a platform message.
|
||||||
private void handlePlatformMessage(final String channel, byte[] message, final int replyId) {
|
private void handlePlatformMessage(final String channel, byte[] message, final int replyId) {
|
||||||
assertAttached();
|
// The platform may not be attached immediately in certain cases where a new bundle is run -
|
||||||
|
// the native view is created in a separate thread. This mostly happens when the app restarts in dev
|
||||||
|
// mode when switching into split-screen mode. Preventing app restarts on layout and density
|
||||||
|
// changes will prevent this, and afterwards this can be changed back to an assert.
|
||||||
|
if (!isAttached()) {
|
||||||
|
Log.d(TAG, "PlatformView is not attached");
|
||||||
|
return;
|
||||||
|
}
|
||||||
BinaryMessageHandler handler = mMessageHandlers.get(channel);
|
BinaryMessageHandler handler = mMessageHandlers.get(channel);
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -267,7 +267,7 @@ public class FlutterView extends SurfaceView
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
mFlutterLifecycleChannel.send("AppLifecycleState.paused");
|
mFlutterLifecycleChannel.send("AppLifecycleState.inactive");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onPostResume() {
|
public void onPostResume() {
|
||||||
@@ -278,7 +278,7 @@ public class FlutterView extends SurfaceView
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
mFlutterLifecycleChannel.send("AppLifecycleState.suspending");
|
mFlutterLifecycleChannel.send("AppLifecycleState.paused");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMemoryPressure() {
|
public void onMemoryPressure() {
|
||||||
|
|||||||
Reference in New Issue
Block a user