0

If the remote control uses bluetooth control, then if the battery is removed / inserted into the remote control, the following events occur: onPause() -> onSaveInstanceState() -> onCreate() -> onStart() -> onRestoreInstanceState() -> onResume(). The application restarts rather than restoring its previous state. The application behaves as if it was hidden, the device ran out of RAM, so the application was destroyed, and then launched as for the first time.

The onSaveInstanceState() event is called, can it be used? My main object is a WebView. Since the app is being destroyed, WebView = null...

What can be done in this situation? I need batteries to not have that much power over my application. For the application to restore its state, or ignore the power of the batteries.

Dmitriy
  • 375
  • 1
  • 18

1 Answers1

0

Implement onSaveInstanceState() in your activity and use a BroadcastReceiver/background service to handle remote control events and trigger the appropriate actions in your application.

You can implement the WebView in a fragment and using setRetainInstance(true) to ensure that it is not destroyed when the activity is destroyed.

CodeCamper
  • 6,609
  • 6
  • 44
  • 94
  • I have tried this: https://stackoverflow.com/a/10258791/10946427. But the webview state was not restored. There was just a white screen. – Dmitriy Feb 23 '23 at 06:46