public static synchronized void initFormCache(Context context) { forms = ModelTranslator.getAllForms(context); prefixes = new String[forms.length]; for (int i = 0; i < forms.length; i++) { prefixes[i] = forms[i].getPrefix(); } }
/* (non-Javadoc) * * @see android.app.IntentService#onHandleIntent(android.content.Intent) */ @Override protected void onHandleIntent(Intent intent) { Log.d("CsvOutputService", "Now being handled: " + intent.getAction()); Form form = ModelTranslator.getFormById(intent.getExtras().getInt("formId")); preferences = getSharedPreferences(CsvOutputScheduler.sharedPreferenceFilename, MODE_PRIVATE); boolean isAutoCsvOn = preferences.getBoolean(form.getFormId() + CsvOutputScheduler.TOGGLE_VAR, false); int autoCsvFrequency = preferences.getInt(form.getFormId() + CsvOutputScheduler.FREQUENCY_VAR, 1); // boolean isDeleteOn = preferences.getBoolean(form.getFormId() + CsvOutputScheduler.DELETE_VAR, // false); Log.d("CsvOutputService.onHandleIntent", form.getFormId() + "_isAutoCsvOn: " + isAutoCsvOn); Log.d( "CsvOutputService.onHandleIntent", form.getFormId() + "_autoCsvFrequency: " + autoCsvFrequency); // service runs for a minute once triggered long endTime = System.currentTimeMillis() + 60 * 1000; while (System.currentTimeMillis() < endTime) { synchronized (this) { try { FormReviewer reviewer = new FormReviewer(); reviewer.outputCSV(form.getFormId()); /* * seems like a bad idea...needs more thought * if (isDeleteOn){ SmsDbHelper dbHelper = new SmsDbHelper(this); final SQLiteDatabase db = dbHelper.getWritableDatabase(); final String table = "formdata_" + form.getPrefix(); final String whereClause = null; final String[] whereArgs = null; int rows = db.delete(table, whereClause, whereArgs); Log.d("CsvOutputService", "deleted " + rows + " records from the form: " + form.getPrefix()); }*/ wait(autoCsvFrequency * 1000); } catch (Exception e) { } } } Log.d( "CsvOutputService", "completed running and ran at intervals of " + autoCsvFrequency + " seconds."); }