use of ca.rmen.android.networkmonitor.app.prefs.PreferencesMigrator in project network-monitor by caarmen.
the class NetMonService method scheduleTests.
/**
* Start scheduling tests, using the scheduler class chosen by the user in the advanced settings.
*/
private void scheduleTests() {
Log.v(TAG, "scheduleTests");
NetMonPreferences prefs = NetMonPreferences.getInstance(this);
PreferencesMigrator prefsMigrator = new PreferencesMigrator(this);
prefsMigrator.migratePreferences();
Class<?> schedulerClass = prefs.getSchedulerClass();
Log.v(TAG, "Will use scheduler " + schedulerClass);
// noinspection TryWithIdenticalCatches
try {
if (mScheduler == null || !mScheduler.getClass().getName().equals(schedulerClass.getName())) {
Log.v(TAG, "Creating new scheduler " + schedulerClass);
if (mScheduler != null)
mScheduler.onDestroy();
mScheduler = (Scheduler) schedulerClass.newInstance();
mScheduler.onCreate(this);
mScheduler.schedule(mTask, prefs.getUpdateInterval());
} else {
Log.v(TAG, "Rescheduling scheduler " + mScheduler);
int interval = prefs.getUpdateInterval();
mScheduler.setInterval(interval);
}
} catch (InstantiationException e) {
Log.e(TAG, "setScheduler Could not create scheduler " + schedulerClass + ": " + e.getMessage(), e);
} catch (IllegalAccessException e) {
Log.e(TAG, "setScheduler Could not create scheduler " + schedulerClass + ": " + e.getMessage(), e);
}
}
Aggregations