OK, DeviceAdminReceiver is a BroadcastReceiver, not an Activity. Right now, your manifest is declaring MainActivity for both components, so one of these declarations is incorrect. MainActivity is a bad name for this class, because it is not an activity, it should probably be MainReceiver or something (just for consistency).
Your application crashes because Android is trying to launch MainActivity , which is not an Activity, as the main activity of your application, which it cannot do.
Also, according to your code, MyActivity is the inner class of this receiver. This is not a paradigm that I would recommend adhering to, and can lead to some confusion. I would define both of these entities as completely separate classes. If one MUST be the inner class of the other, BroadcastReceiver will make more sense as an inner class of Activity .
In BARE MINIMUM, if you do not reorganize any of your Java code, you need to update the manifest to reference the relevant elements based on what you wrote, which means a reference to the actual activity as an inner class.
<activity android:name=".MainActivity$MyActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name=".MainActivity" android:permission="android.permission.BIND_DEVICE_ADMIN" > <meta-data android:name="android.app.device_admin" android:resource="@xml/device_admin_sample" /> <intent-filter> <action android:name="android.app.action.DEVICE_ADMIN_ENABLED" /> </intent-filter> </receiver>
It may take some time to re-examine the sample device administration API in the SDK, which is located in
<SDK location>/samples/<platform-version>/ApiDemos/src/com/example/android/apis/app/DeviceAdminSample.java
on your computer.
source share