finishOnCloseSystemDialogs solves Android screen problems

question

In the past HMI development, some problems encountered can be solved by configuring finishOnCloseSystemDialogs:
1. When the singleTask screen is in the background, after pressing the Home button, it goes through the onStart–onResume–onPause–onStop life cycle.
2. During the screen display, Press Home, and when returning to this screen, the previous content will flash.

This can be solved by configuring the following content in the Activity of AndroidManifest

// 当关闭系统窗口请求出现时,是否销毁Activity
// true为销毁
android:finishOnCloseSystemDialogs="true"

principle

Why does this happen? Because when you press the Home button, the system will send out an Intent.ACTION_CLOSE_SYSTEM_DIALOGS broadcast to close the system Dialog.
After Activity is configured with the above content, it will go through the destroy process.

In addition, if you want to monitor the Home button, you can also broadcast through ACTION_CLOSE_SYSTEM_DIALOGS.

BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    
    
	@Override
	public void onReceive(Context context, Intent intent) {
    
    
		if (intent.getAction().equals(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) {
    
    
			String reason = intent.getStringExtra("reason");
			if ("homekey".equals(reason)) {
    
    
				// Do something
			}
		}
	}
};

Reference articles:
https://blog.csdn.net/ekeuy/article/details/39400939
https://www.cnblogs.com/cj5785/p/9893156.html

Guess you like

Origin blog.csdn.net/cshoney/article/details/120066614