android:persistent
2016-10-28 本文已影响0人
yuansip
Case A
- Install test app with versionCode=1 and versionName=0.1.0 and android:persistent=true to /system/app
- Start it and press 'Back', then execute 'ps | grep <test app>' to get the pid
- Keep android:persistent=true, change versionCode to 2, versionName to 0.2.0 and replace MainActivity's AFragment tab to BFragment, so it is supposed that MainActivity should have 2 BFragment tab now.
- Build and install the newer test app to /data/app
- Execute 'ps | grep <test app>' to get the pid, you can see the pid is not changed.
- Start the test app by clicking the launch icon, you can see the MainActivity does not replace AFragment with BFragment, but the versionName in 'Settings->Version' has already be changed to 0.2.0. And the pid is changed.
- Reboot the devices, Start the test app by clicking the launch icon, you can see now the MainActivity replaces AFragment with BFragment and the versionName in 'Settings->Version' is 0.2.0
Case B
- Install test app with versionCode=1 and versionName=0.1.0 and android:persistent=true to /system/app
- Start it and press 'Back', then execute 'ps | grep <test app>' to get the pid
- Change android:persistent to false, versionCode to 2, versionName to 0.2.0 and replace MainActivity's AFragment tab to BFragment, so it is supposed that MainActivity should have 2 BFragment tab now.
- Build and install the newer test app to /data/app
- Execute 'ps | grep <test app>' to get the pid, you can see the pid is not changed .
- Start the test app by clicking the launch icon, you can see the MainActivity does not replace AFragment with BFragment, but the versionName in 'Settings->Version' has already be changed to 0.2.0. And the pid is changed.
- Reboot the devices, Start the test app by clicking the launch icon, you can see now the MainActivity replaces AFragment with BFragment and the versionName in 'Settings->Version' is 0.2.0
Case C
- Install test app with versionCode=1 and versionName=0.1.0 and android:persistent=false to /system/app
- Start it and press 'Back', then execute 'ps | grep <test app>' to get the pid
- Keep android:persistent=false, change versionCode to 2, versionName to 0.2.0 and replace MainActivity's AFragment tab to BFragment, so it is supposed that MainActivity should have 2 BFragment tab now.
- Build and install the newer test app to /data/app
- Execute 'ps | grep <test app>' to get the pid, you can see the pid is changed.
- Start the test app by clicking the launch icon, you can see now the MainActivity replaces AFragment with BFragment and the versionName in 'Settings->Version' is 0.2.0.
Case D
- Install test app with versionCode=1 and versionName=0.1.0 and android:persistent=false to /system/app
- Start it and press 'Back', then execute 'ps | grep <test app>' to get the pid
- Change android:persistent to true, versionCode to 2, versionName to 0.2.0 and replace MainActivity's AFragment tab to BFragment, so it is supposed that MainActivity should have 2 BFragment tab now.
- Build and install the newer test app to /data/app
- Execute 'ps | grep <test app>' to get the pid, you can see the pid is changed .
- Start the test app by clicking the launch icon, you can see now the MainActivity replaces AFragment with BFragment and the versionName in 'Settings->Version' is 0.2.0.
- Keep android:persistent= true, change versionCode to 3, versionName to 0.3.0 and recover MainActivity's BFragment tab back to AFragment, so it is supposed that MainActivity should both have AFragment and BFragment tab again now.
- Build and install the newer test app to /data/app
- Execute 'ps | grep <test app>' to get the pid, you can see the pid is changed .
- Start the test app by clicking the launch icon, you can see now the MainActivity has both AFragment and BFragment, and the versionName in 'Settings->Version' is 0.3.0.
Conclusion
Android:persistent flag of System.App has more priority then its upgraded Data.App. I suggest set android:persistent to false, otherwise it will be messed up when user tries to upgrade the pre-installed (system/app/) app from any Application Market.