I am working on a daily devotional app but I need to get the right information on a problem.
I made the app offline where I set each day with a corresponding content. However, I want to correctly show set content for a day automatically when the user opens the app.
For example, if today was 21st of January, and the user opens the app it should immediately show contents for that day. How do I implement this. Any ideas would be appreciated.
Well you need to maintain DataBase (in SQL lite or ROOM (android)) so put your data into your database then whenever you needed just you need to call query to fetch data and show your content accordingly.
Follow step :-
Need to create DB and make your table related to content.
Put your data according to your requirement (means how you want to show on your content into your app)
Last when ever you open your app then you need to fire query from data base according to your date.
After fetching data from your query you just need to put data into your UI.
Room in android.
SQL in android
From where ever you are fetching content just pass the current date and get the data with respect to that date. If you are fetching content from local db you could use a simple sql query like :
"select * from content where date = " + date + " ;";
Related
I want to make an android app that works offline. For the data part, I want to have some data in a json file, and whenever my app is open firstly that JSON file is fetched, and from the fetched data I want to make tables entries in android room database(offline). So that, let say if user liked some quotes, then i can change the state of that quote as liked in room db, and when user clicked on Liked Quotes navigation, I can show those offline stored quotes which were liked (OfCourse when user delete the app that data will be lost). The problem I'm facing is where to fetch that data file and create entries in room db. If I do this in onCreate() then whenever user will open this app the duplicate entries will be created everytime. How to make those entries only ones?
There's several ways to do it. One way is to include a random UUID in each element, and make that column in the DB have a UNIQUE constraint. Then re-adding it will fail (alternatively you can use an UPSERT and then it will automatically update the data in case the data changed).
Another way is to just not process the file if it already exists in onCreate. Your logic can be
if(network_exists) {
copy_file_from_network()
}
else if(json file exists) {
return
}
else {
copy_file_from_assets()
}
process_json_file()
Actually I can see a good argument for doing both- that way if there are updates to existing rows you process them, but if there's no new data you don't waste your time.
As for a good place to put this- I'd be running this during your splash screen if you have one, so the user has an indication that you may be processing for a while.
I am developing an Odoo 8 (OpenERP) application. That application use postgresql database. In backend of Odoo 8, there is add sale order button. So, I want to know, how to know the changing data in the last 5 seconds? My need is I want to insert data from mobile apps. What tables that that changing? Any query for do that? Or another suggest.
the database has 314 tables. Is there application of part3 like MONYog may be?
Any help is very appreciate.
For this kind of situation, there is one best way to manage as
Use always two columns in each table as "CreatedOn" and "LastUpdatedOn", and insert proepr values in it as on create time add current time in both then on every update just change last updated on by current time so you will easily get data as per your requirement.
You could also add a function like this:
create or replace function notify_table_change() RETURNS TRIGGER
LANGUAGE PLPGSQL AS
$$
NOTIFY all_writes TG_RELNAME;
IF TG_OP = 'DELETE' THEN RETURN OLD; ELSE RETURN NEW; END OF;
$$;
Then you could add the trigger for all inserts, updates, and deletes (but not truncate since I didn't handle that).
Then te client can:
LISTEN all_writes;
And will get live notifications of which tables are updated in real time.
Monitoring database feels a bit strange approach to the problem. Writing custom modules for odoo (and OpenERP) is very simple and staightforward. I'd create module which triggers whatever you want to do.
Here is a brief example of simplest OpenERP / odoo module:
from osv import osv
class my_custom_module(osv.osv):
_inherit = 'sale.order'
_name = 'sale.order'
def create(self, cr, uid, vals, ctx={}):
<your code here, whatever you want to do when new sale.order obejcet is created >
return super(my_custom_module, self).create(cr, uid, vals, ctx)
my_custom_module()
Does this help?
In a live commercial app. The method I use is a creation and update date/time stamp column.
Example
create table foo (
foo_id serial not null unique,
created_timestamp timestamp not null default current_timestamp,
updated_timestamp timestamp not null default current_timestamp
) with oids;
The trigger to do the work
CREATE TRIGGER check_table_to_do_update
--What i want to do
The trigger on the table
CREATE TRIGGER check_update_foo
AFTER UPDATE ON foo
FOR EACH ROW
WHEN (OLD.updated_timestamp IS DISTINCT FROM NEW.updated_timestamp)
EXECUTE PROCEDURE check_table__to_do_update();
Anything else can put an unnecessary overhead on the system.
All the best
In my Android app I have an activity with a listview that displays about 4000 items that are stored
locally in a SQLite Database. If I make an edit to an item, how can I get only this change in the listview,
without having to refresh all the item list (which means a new query for 4000 results)? This query slows down the performance.
I would like something like NSFetchedResultsController of ios.
Strategy should be -
As you are editing the contact, if the update is successful you just fetch the latest info from db for this specific contact only.
Update the edited contact object in your adapter's source List/Array's specific position.
Invoke your adapter.notifyDataSetChanged().
you must have an id for each contact in your SQL lite database.
when you edit a contact update that specific record in your database on basis of the id.
if update is successfull means the information you sent to database is stored successfully .
now you can use the same informtion to update your ArrayList/HashMap whatever you are using to populate your listview.
Ex:- suppose you edited 3rd index contact in your listview on successfull update you add like yourarraylist.add(3,contact);
and the fire notifydatasetChanged.
Try these steps if possible:
Try to fetch the data from db, but do it in different thread which won't effect the main UIThread.
Then you can call the adapter.notifyDataSetChanged() on adapter object. It will do the job i hope :).
I am relatively new to Android and SQLite, I was wondering I can create basic form input where user can input his data to be added to SQLite table
When it comes to selecting the day, Monday, tuesday...etc is it possible to compare current day that was added in SQLite to real time day so that for example if its monday, it will retrieve all data with "Monday" as their Day column.
If I want to retrieve all reminders is it possible to retrieve all reminders throughout the week and place them not in an exapandable view but in the associated header day so for example in the same list each day will have a header "Monday" and all monday reminders will be placed in the monday header, will this mean I need multiple ListViews, I will be implementing this on a Fragment
I want to know what you actually want to ask?
1. you can put users' input data into sqlite database
2. put into the db table you created with values(input data & current date)
3. get data from the database when needed, and calculate the date difference and create a listview by asynctask.
i have no reputation to write a comment but want to give u some help. hope you add some comment about what you want to know about specifically in detail.
Thanks in advance.
I am developing a Car Review Application, where user can log in and displayed all the review from the Database. All the the data is being stored in MYSQLdatabase first. I am using json to connect to the MYSQLdatabase and SQLiteDatabase. But the problem is that, after log in the application screen huge no. of data is coming from the server and it is being inserted in our SQLite Database.
After that it is being retrieved from database and displayed in the Application Screen in a list view, it is taking a longer time to displayed all the data in list view. In that case, I am using a SimpleCursorAdapter to retrieve all the data from database.
So is there any way like pagination or something like that to make the data retrieval faster.
Please help me by giving some source code.
You can use something like:
Page 1:
SELECT * FROM YOUR_TABLE LIMIT 20 OFFSET 0
Page 2:
SELECT * FROM YOUR_TABLE LIMIT 20 OFFSET 20
Reference: http://sqlite.org/lang_select.html
You can use the concept of Asynchronous tasks along with SimpleCursorAdapters.
"AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers."
Here's what you can do:
1) Retrieve only 1st 10/15 items in the 1st query.
2) Fire another query as a background task, while user is checking out first 10/15 items.
This will certainly make the User experience faster
Using the LIMIT keyword from MYSQL you can achieve pagination.
LIMIT allows you to control the number of rows returned by query:
Example:
to show first 10 records
SELECT * FROM Student LIMIT 10 //for first time
to show rows between 10 and 20
SELECT *FROM Student LIMIT 9, 10 //after showing the records first time
LIMIT works for SQLiteDatabase also