I have an Android database hosted in Parse and I am trying to find the best way / methods to update my LocalStorage with the latest deleted changes.
I am not asking for code or syntax, I just wanted to follow a series of steps to follow, I’m sure I will need to use a workflow because I don’t want to block the user interface, I would like the transition to be as smooth as possible for the user ( he didn’t even realize that an update was happening), and I want this to happen when the application is in the foreground. Ideas I have received so far:
- Use multithreading (Loopers, Handlers, Thread) and update each table in a separate thread.
- Try to suppress the query to minimize CPU usage and get the table at a time.
- Use the bootloader and just listen to the changes.
- Call IntentService to get table by table.
- Create an Unbound Service and update the database after closing the application.
- Do not update the database in the background and wait for the user to really require the data and retrieve it.
I already tried IntentService, it is not as smooth as we would like:
public class DataService extends IntentService {
public DataService() {
super(DataService.class.getName());
}
@Override
protected void onHandleIntent(Intent intent) {
String[] entities = {
"Img",
"Pack",
"Technology",
"Term",
"TermHierarchy",
"TermImplementation",
"TermTerm",
"UserTechnology",
"UserTerm",
};
for (String entity : entities) {
updateLocalTable(entity);
}
}
private void updateLocalTable(String entity) {
ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(entity);
query.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null){
ParseObject.pinAllInBackground(objects);
}else {
Log.e(TAG_, e.toString());
}
}
});
}
}
In addition, I call it the first time I change the connection (Wi-Fi is available). Should I instead just call it onCreate or create an alarm to update once at a certain specific time or only after the Activity is completed?
I saw several related posts:
Update data in the background Periodically (Android)
Android SQL-, -
(mysql) sqlite
, .
, Parse RESTful JSON, .
Edit.
, ( , @gsgsgs) 2 :
https://www.youtube.com/watch?v=Expbi0lHLRE