15

What is use of android:persistent="true" properties?

<application
    android:fullBackupContent="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:persistent="true"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme1">
</application>
Jason Saruulo
  • 1,837
  • 4
  • 21
  • 21
Alis
  • 193
  • 1
  • 2
  • 10

3 Answers3

29

Unfortunately, for most developers there is no use. The official guide for android:persistent has a weakly worded comment that it is "intended" for system apps. To be clear, this property is ignored unless you are a system app.

You can see in the commit where flag checking was added to PackageManager, this requires both the persistent flag and the system app flag. If your app only has one of these, it will not be treated as persistent.

So this property is only useful for platform developers and hardware vendors. Sorry.

But what does it do? This property allows you to start a background service on Oreo and prevents it from being automatically killed.

Brent K.
  • 927
  • 1
  • 11
  • 16
  • this is the more effective and right answer. Persistent property is ignored unless you're building a system application (usually you can't do this unless working on your own AOSP build or, maybe, on a rooted android device) – amonthedeamon Nov 28 '19 at 14:49
  • Hello @Brent.K I am doing system apps but where exactly do I need to change it to make it persistant to work in framework side? – Shadow Jan 09 '20 at 13:44
  • 1
    Hi @Shadow This is a property of your AndroidManifest.xml. It goes in the application tag: – Brent K. Jan 10 '20 at 14:22
  • Say I am making a system application and I am making it persistent by setting this flag to true. Can this application be updated like any other system app? or can it be updated only through system update? – jaga Aug 23 '23 at 09:36
13

Read official guide line about android:persistent

Whether or not the application should remain running at all times — "true" if it should, and "false" if not. The default value is "false". Applications should not normally set this flag; persistence mode is intended only for certain system applications.

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
0

There is a big danger with this, and very poorly documented. If you tag your system app as persistent, it can not be removed/updated/replaced or anything. It is locked in for good on the device and stays running. From a developer perspective, I am having great dificulty updating it to a newer version. Once installed in your device image, that is it.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 04 '23 at 00:13