fix array out of bounds error and some compilation issues.
Copy required fields of the history item associated with a widget to SharedPreferences