File tree Expand file tree Collapse file tree 4 files changed +40
-7
lines changed
android/src/main/java/app/tauri/plugin Expand file tree Collapse file tree 4 files changed +40
-7
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' tauri ' : ' patch:enhance'
3+ ---
4+
5+ Add support for onResume and onPause events in android plugins.
Original file line number Diff line number Diff line change @@ -13,15 +13,18 @@ import app.tauri.plugin.PluginManager
1313abstract class TauriActivity : WryActivity () {
1414 var pluginManager: PluginManager = PluginManager (this )
1515
16- override fun onCreate (savedInstanceState : Bundle ? ) {
17- super .onCreate(savedInstanceState)
18- if (intent != null ) {
19- pluginManager.onNewIntent(intent)
20- }
21- }
22-
2316 override fun onNewIntent (intent : Intent ) {
2417 super .onNewIntent(intent)
2518 pluginManager.onNewIntent(intent)
2619 }
20+
21+ override fun onResume () {
22+ super .onResume()
23+ pluginManager.onResume()
24+ }
25+
26+ override fun onPause () {
27+ super .onPause()
28+ pluginManager.onPause()
29+ }
2730}
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import android.app.Activity
88import android.content.Intent
99import android.content.pm.PackageManager
1010import android.net.Uri
11+ import android.os.Bundle
1112import android.webkit.WebView
1213import androidx.core.app.ActivityCompat
1314import app.tauri.FsUtils
@@ -59,6 +60,17 @@ abstract class Plugin(private val activity: Activity) {
5960 */
6061 open fun onNewIntent (intent : Intent ) {}
6162
63+
64+ /* *
65+ * This event is called just before another activity comes into the foreground.
66+ */
67+ open fun onPause () {}
68+
69+ /* *
70+ * This event is called when the user returns to the activity. It is also called on cold starts.
71+ */
72+ open fun onResume () {}
73+
6274 /* *
6375 * Start activity for result with the provided Intent and resolve calling the provided callback method name.
6476 *
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package app.tauri.plugin
66
77import android.content.Context
88import android.content.Intent
9+ import android.os.Bundle
910import android.webkit.WebView
1011import androidx.activity.result.ActivityResult
1112import androidx.activity.result.ActivityResultLauncher
@@ -71,6 +72,18 @@ class PluginManager(val activity: AppCompatActivity) {
7172 }
7273 }
7374
75+ fun onPause () {
76+ for (plugin in plugins.values) {
77+ plugin.instance.onPause()
78+ }
79+ }
80+
81+ fun onResume () {
82+ for (plugin in plugins.values) {
83+ plugin.instance.onResume()
84+ }
85+ }
86+
7487 fun startActivityForResult (intent : Intent , callback : ActivityResultCallback ) {
7588 startActivityForResultCallback = callback
7689 startActivityForResultLauncher.launch(intent)
You can’t perform that action at this time.
0 commit comments