Repository: godot
Issue: [Android] In the Vulkan renderer, NOTIFICATION_APPLICATION_PAUSED and NOTIFICATION_APPLICATION_RESUMED are duplicated
Labels: bug,platform:android,topic:porting

### Tested versions

v4.2.1.stable.official.b09f793f5, v4.3.dev4.official.df78c0636



### System information

Vulkan (mobile), Android 10

### Issue description

The Vulkan version on Android emits NOTIFICATION_APPLICATION_PAUSED and NOTIFICATION_APPLICATION_RESUMED notifications twice.
It is expected to be notified only once, the same behavior as in gles3.

### Logcat

**mobile (vulkan) - issue**

v 4.2.1.stable

```
02-29 11:15:13.453 26627 26663 I godot   : Godot Engine v4.2.1.stable.official.b09f793f5 - https://godotengine.org
02-29 11:15:13.543 26627 26663 I godot   : Vulkan API 1.1.124 - Forward Mobile - Using Vulkan Device #0: Qualcomm - Adreno (TM) 610
02-29 11:15:14.915 26627 26663 I godot   :  
02-29 11:15:15.691 26627 26663 I godot   : _notification: 2000 
02-29 11:15:15.693 26627 26663 I godot   : _notification:   30 
02-29 11:15:23.791 26627 26663 I godot   : _notification: 1005 NOTIFICATION_WM_WINDOW_FOCUS_OUT
02-29 11:15:23.810 26627 26663 I godot   : _notification: 2015 NOTIFICATION_APPLICATION_PAUSED    <- one
02-29 11:15:23.810 26627 26663 I godot   : _notification: 2015 NOTIFICATION_APPLICATION_PAUSED    <- two

...

02-29 11:15:59.139 26627 26663 I godot   : _notification: 2014 NOTIFICATION_APPLICATION_RESUMED    <- one
02-29 11:15:59.139 26627 26663 I godot   : _notification: 1004 NOTIFICATION_WM_WINDOW_FOCUS_IN
02-29 11:15:59.202 26627 26663 I godot   : _notification: 2014 NOTIFICATION_APPLICATION_RESUMED    <- two
```
<details><summary>v 4.3.dev4</summary>
<p>

```
03-01 11:33:22.461 10012 10047 I godot   : Godot Engine v4.3.dev4.official.df78c0636 - https://godotengine.org
03-01 11:33:22.552 10012 10047 I godot   : Vulkan 1.1.124 - Forward Mobile - Using Device #0: Qualcomm - Adreno (TM) 610
03-01 11:33:22.696 10012 10047 I godot   : 
03-01 11:33:23.417 10012 10047 I godot   : _notification: 2000 
03-01 11:33:23.419 10012 10047 I godot   : _notification:   30 
03-01 11:33:27.254 10012 10047 I godot   : _notification: 1005 NOTIFICATION_WM_WINDOW_FOCUS_OUT
03-01 11:33:27.254 10012 10047 I godot   : _notification: 2017 NOTIFICATION_APPLICATION_FOCUS_OUT
03-01 11:33:27.255 10012 10047 I godot   : _notification: 2015 NOTIFICATION_APPLICATION_PAUSED    <- one
03-01 11:33:27.300 10012 10047 I godot   : _notification: 2015 NOTIFICATION_APPLICATION_PAUSED    <- two

...

03-01 11:33:39.778 10012 10047 I godot   : _notification: 2014 NOTIFICATION_APPLICATION_RESUMED    <- one
03-01 11:33:39.778 10012 10047 I godot   : _notification: 1004 NOTIFICATION_WM_WINDOW_FOCUS_IN
03-01 11:33:39.778 10012 10047 I godot   : _notification: 2016 NOTIFICATION_APPLICATION_FOCUS_IN
03-01 11:33:39.839 10012 10047 I godot   : _notification: 2014 NOTIFICATION_APPLICATION_RESUMED    <- two
```
</p>
</details>


**gl_compatibility (OpenGL ES) - no issue**
<details><summary>v 4.2.1.stable</summary>
<p>

```
02-29 11:06:12.346 25057 25183 I godot   : Godot Engine v4.2.1.stable.official.b09f793f5 - https://godotengine.org
02-29 11:06:12.908 25057 25183 I godot   : OpenGL API OpenGL ES 3.2 V@444.0 (GIT@39a1dfd, Ic628754133, 1593471350) (Date:06/29/20) - Compatibility - Using Device: Qualcomm - Adreno (TM) 610
02-29 11:06:12.919 25057 25183 I godot   :  
02-29 11:06:13.788 25057 25183 I godot   : _notification: 2000 
02-29 11:06:13.790 25057 25183 I godot   : _notification:   30 

02-29 11:06:26.708 25057 25183 I godot   : _notification: 1005 NOTIFICATION_WM_WINDOW_FOCUS_OUT
02-29 11:06:26.719 25057 25183 I godot   : _notification: 2015 NOTIFICATION_APPLICATION_PAUSED

...

02-29 11:07:00.460 25057 25183 I godot   : _notification: 1004 NOTIFICATION_WM_WINDOW_FOCUS_IN
02-29 11:07:00.520 25057 25183 I godot   : _notification: 2014 NOTIFICATION_APPLICATION_RESUMED
```
</p>
</details>
<details><summary>v 4.3.dev4</summary>
<p>

```
03-01 11:37:57.668 10603 10639 I godot   : Godot Engine v4.3.dev4.official.df78c0636 - https://godotengine.org
03-01 11:37:57.787 10603 10639 I godot   : OpenGL API OpenGL ES 3.2 V@444.0 (GIT@39a1dfd, Ic628754133, 1593471350) (Date:06/29/20) - Compatibility - Using Device: Qualcomm - Adreno (TM) 610
03-01 11:37:57.802 10603 10639 I godot   : 
03-01 11:37:58.579 10603 10639 I godot   : _notification: 2000 
03-01 11:37:58.581 10603 10639 I godot   : _notification:   30 
03-01 11:38:02.535 10603 10639 I godot   : _notification: 1005 NOTIFICATION_WM_WINDOW_FOCUS_OUT
03-01 11:38:02.536 10603 10639 I godot   : _notification: 2017 NOTIFICATION_APPLICATION_FOCUS_OUT
03-01 11:38:02.537 10603 10639 I godot   : _notification: 2015 NOTIFICATION_APPLICATION_PAUSED

...

03-01 11:38:17.211 10603 10639 I godot   : _notification: 1004 NOTIFICATION_WM_WINDOW_FOCUS_IN
03-01 11:38:17.212 10603 10639 I godot   : _notification: 2016 NOTIFICATION_APPLICATION_FOCUS_IN
03-01 11:38:17.277 10603 10639 I godot   : _notification: 2014 NOTIFICATION_APPLICATION_RESUMED
```
</p>
</details>

### Details

I will only show the Pause. Resumed follows the same path.

Android onPause() -> VkRenderer.onVkPause() -> NOTIFICATION_APPLICATION_PAUSED
Android onStop() -> VkThread.onPause() -> VkRenderer.onVkPause() -> NOTIFICATION_APPLICATION_PAUSED

<details><summary>program flow [notification = NOTIFICATION_APPLICATION_PAUSED]</summary>
<p>

```
# Android 
GodotFragment.onPause() -> Godot.onPause() -> renderView.onActivityPaused() -> GL or Vulkan renderView
GodotFragment.onStop() -> Godot.onStop() -> renderView.onActivityStopped() -> GL or Vulkan renderView

# GL render view
GodotGLRenderView.onActivityPaused() ->  {GodotLib.focusout(); GodotRenderer.onActivityPaused()} -> GodotLib.onRendererPaused() -> notification
GodotGLRenderView.onActivityStopped() -> GLSurfaceView.pauseGLThread() -> GLThread.onPause()

# Vulkan render view - issue
GodotVulkanRenderView.onActivityPaused() -> {GodotLib.focusout(); VkRenderer.onVkPause()} -> GodotLib.onRendererPaused() -> notification
GodotVulkanRenderView.onActivityStopped() -> VkSurfaceView.pauseRenderThread() -> VkThread.onPause() -> VkRenderer.onVkPause() -> GodotLib.onRendererPaused() -> notification
```
</p>
</details>

https://github.com/godotengine/godot/blob/7d2ca2d8ac49cde9767e00b70f9eaf1920eb266d/platform/android/java/lib/src/org/godotengine/godot/vulkan/VkThread.kt#L203-L208

I'm not sure what the implications are of removing vkRenderer.onVkPause() and vkRenderer.onVkResume().
And/or implement onStop() and send NOTIFICATION_APPLICATION_STOP.

> onPause() execution is very brief and does not necessarily offer enough time to perform save operations. 
Activity lifecycle - [Documentation](https://developer.android.com/guide/components/activities/activity-lifecycle#onstop)

### Steps to reproduce

Create simple scene. Attach notification.gd script to the selected node. 
Remote debug and "rendering/renderer/rendering_method.mobile" = mobile
Run it on an Android device.
On the Android device, it switches application and then returns a few moments later.

adb logcat -s godot

<details><summary>notification.gd</summary>
<p>

```gdscript

extends Node2D

func _notification(what: int):
	var name: String = ""
	
	match what:
		# 4.0 Android, 4.3 Android and iOS
		NOTIFICATION_APPLICATION_PAUSED:
			name = "NOTIFICATION_APPLICATION_PAUSED"
		NOTIFICATION_APPLICATION_RESUMED:
			name = "NOTIFICATION_APPLICATION_RESUMED"	
		
		# 4.0 Desktop, 4.3 Desktop and mobile
		NOTIFICATION_APPLICATION_FOCUS_IN:
			name = "NOTIFICATION_APPLICATION_FOCUS_IN"
		NOTIFICATION_APPLICATION_FOCUS_OUT:
			name = "NOTIFICATION_APPLICATION_FOCUS_OUT"
		
		# 4.0 All
		NOTIFICATION_WM_WINDOW_FOCUS_IN:
			name = "NOTIFICATION_WM_WINDOW_FOCUS_IN"
		NOTIFICATION_WM_WINDOW_FOCUS_OUT:
			name = "NOTIFICATION_WM_WINDOW_FOCUS_OUT"
	
	print("_notification: %4d %s" % [what, name])
```
</p>
</details> 

### Minimal reproduction project (MRP)

[godot-issue-android-notification.zip](https://github.com/godotengine/godot/files/14466504/godot-issue-android-notification.zip)