Android: Device Admin: Why should Activity be an inner class of the DeviceAdminReceiver class?

StackOverflow https://stackoverflow.com/questions/10581183

  •  08-06-2021
  •  | 
  •  

Domanda

Many posts I read state that the Activity should be an inner class of the DeviceAdminReceiver, but I can't understand why this should be the case.

The android documentation doesn't make such a statement either, though their sample is like that.

Is this an actual requirement ? If so, does this mean that it cannot be invoked using a service ?

È stato utile?

Soluzione

Ok, found the answer hidden in the source code of the sample application.

/**
 * <p>UI control for the sample device admin.  This provides an interface
 * to enable, disable, and perform other operations with it to see
 * their effect.</p>
 *
 * **<p>Note that this is implemented as an inner class only keep the sample
 * all together; typically this code would appear in some separate class.**
 */

Is stated just above the inner class (the activity), which indicates that it does NOT have to be an inner class and what is recommended is for these two classes to be separated.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top