i have an android app that gets data from mysql database, now i want to implement refreshing capabilities such that when new entry is entered int the database then everyone having the app will be able to see the new entry after sometimes even without restarting the app again. how can i do that.?
i have tried to use
Intent i = getIntent();
finish();
startActivity(i);
but it does not do what i want as it refresh the activity but does not load new entries.
You have to implement the code to fetch the new data from the db and update the entries in your onResume() method of this activity for your code to work.
If by entries, you are using a ListView, you could also use adapter.notifyDataSetChanged() to refresh the data without having to finish and restart the entire activity. (Taken from this post)
In your Activity you will be calling a API to get data from mysql Database. Now you need to call that API after a fixed interval of time to get data from mysql database again.
If new entry is added into the database you need to send push notification to all users about the updation. You can also implement automatic refresh when such notification is received by the users.
Related
I am using Action on google Java client library in my webhook code.How to retrieve data from user storage after switching to an event.
I am setting some value in user storage and switched to an custom event using EventInput from my webhook.After I triggered another Intent, the user storage gets clear and it is empty in ActionRequest.
How to retrieve data from user storage after switching to an custom event?
I want to implement chat between two users in mobile, I'm using android studio and store the messages in AWS(amazon) MySQL database.
I manage to read messages every time user starts the chat activity like so:
void onCreate() {
readHistoryMessagesFromLocalDataBase();
readMessagesFromGlobalDataBase();
}
The first function is used to read the history messages from the local database of Android using SQLite.
The second function is used to read any new messages waiting on the global database of Amazon using MySQL.
This works perfectly, but how can I receive messages in real time while I'm already in the activity without reloading or refreshing?
Is there any data change listener to achieve this goal?
I have Content provider and sync adapter in my project.
In my project first i'm going to fetch data from server and then i'm storing it in my database sqlite.
Now i'm coming to my issue. Actually i want to change the server data according to the data modified in the sqlite.
For example: if i delete data in my database i also want to delete data in my server database. For this purpose my sync adapter should know what operation is performed like delete or insert.
Another way of doing this is comparing my whole local sqlite database with the data in the server when the sync adapter is invoked.
I don't want that approach. Is there any way to know who is invoking sync adapter or what operation is performed in content provider from sync adapter?
The term "who is invoking sync adapter" seems not valuable, as long as that would give you no useful information. Instead, you most probably would like to pass some params at the time when someone is asking for a sync (via requestSync()).
ContentResolver.requestSync(Account, String, Bundle) accepts an extra Bundle that will be passed to your SyncAdapter's onPerformSync():
// a code that initiates sync
ContentResolver.requestSync(ACCOUNT, AUTHORITY, someBundle);
...
// your implmementation of SyncAdapter
#Override
public void onPerformSync(
Account account,
Bundle extras, // acquire information from this bundle
String authority,
ContentProviderClient provider,
SyncResult syncResult) {
/*
* Put the data transfer code here.
*/
...
}
Now, I save data in datastore of google cloud.
module-backend
#Entity
public class ComprarProducto {
#Id
private String producto;
private boolean comprado;
public ComprarProducto() {
}
public ComprarProducto(String producto) {
this.producto = producto;
this.comprado = false;
}
...
}
Example data of CompraProducto
This data is displayed in a listview. When I add one item, the list is updated and saved in datastore.For save data I use AsyncTask in app.
Then, If I add one item in device1, I want to see that listview as both device1 as device2 is updated, but I don't know how to do it.
I use too GCM (google cloud messaging) and I've got to send a message to devices but only this. I want to see the data update in the device 2 without taking any action.
I want to see the data update in the device 2 without taking any
action.
This is not possible without somehow notifying from the backend server that new data has been saved to datastore. Sending a push notification to device2 (or all other devices or whatever) would definitely be the correct way to do it. What you do is have the push notification tell device2 to query datastore.
If you really don't want to use GCM you COULD have device2 just query datastore every couple minutes but that is not recommended. The correct way to do it is to use GCM to give your device2 a "tickle" to indicate that there is new data in datastore and to query accordingly.
Not sure what kind of app you are building but these are some options.
I have a project setup. https://github.com/Axiom1999/Iron-Banner-Companion/blob/master/app/src/main/java/me/axiom/aapp/ironbannercompanion/
And I have a button which I need to check with the API if the username on the platform exists and if it can get information then start the MainActivity intent.
I do not know how to initially start the connection.
You can use LoginActivity for checking if user already exists. Check this out in onCreate() (i think the best way keep this data in SharedPreferences). If user exists try to login and show LoginActivity with ProgressBar. If user does not exists simply show Login/SignUpActivity