Right now, I'm working on a project that involves fetching movie data from the MovieDB. I'm using Schematic as my Content Provider Generator to avoid the headache of making one. Works fine so far.
The problem I'm asking here is how my code is structured. Right now, my fragment that includes the AsyncTask calls the task to fetch data, which is called everytime the app loads the MainActivity. Data is fetched and inserted into the database table fine; cursors don't return null and get the data I stored. However, I'm running into this what I believe to be an issue where I fetch the data again and store it into the same database. This happens if I load into a DetailActivity, SettingsActivity, or any other activity that navigates away from the MainActivity but will return to it through a back button.
Log statements appear to show that my data is re-inserting again, resulting in double and so forth of the same entries in the same database table. I can think of a few temporary solutions, one of which is to remove the call to fetch data on starting the app, instead fetching data through the use of a refresh button on the Action Bar. Another is perhaps making a column of the table unique, particularly the youtube video key string that holds the key for a youtube video. I'm still unsure of what to do at this point.
Any solutions I would greatly appreciate. Thanks.