I'm trying to understand if the user has enabled the admin or not and LATER update a checkbox (in onResume).
The problem is that the activity which allows the user to enable the admin is launched and it's launched the following code without waiting for the user decision. How could bypass it?
private void doAttivaRimuoviAdmin() {
if (isAdminAttivo()) {
mDPM.removeActiveAdmin(mDeviceAdminSample);
} else {
Intent localIntent = new Intent("android.app.action.ADD_DEVICE_ADMIN");
localIntent.putExtra("android.app.extra.DEVICE_ADMIN", mDeviceAdminSample);
localIntent.putExtra("android.app.extra.ADD_EXPLANATION",
getString(R.string.spiegazione_amministratore));
startActivityForResult(localIntent, 1);
// se non รจ stato dato il permesso, non attiva la checkbox
Editor e = mPrefs.edit();
if (isAdminAttivo()) {
e.putBoolean("spegnischermoabilitato", true);
} else {
e.putBoolean("spegnischermoabilitato", false);
}
e.commit();
Log.i(getString(R.string.app_name), ""+ mPrefs.getBoolean("spegnischermoabilitato", false));
}
}
In poor words, the sharedpreference "spegnischermoabilitato" always has FALSE within it.