I have created a list view just like a whatsapp chats list which is working fine it is loading data from server and setting its view but the problem is when the device is offline it cannot show the view which was previsouly created so my question is how to save the list view offline so that when the device is online my app recieves views from server and if the device is offline then the app should show views which were previously loaded.
And if possible please share some tutorials related to this.
You need to save your data locally using database. The most common option is sqlite. You can try this tutorial to understand what to do: http://www.tutorialspoint.com/android/android_sqlite_database.htm there are some options like Sugar Orm (or any other ORM) which uses sqlite in the background but makes it easy to work with objects (the shortage is that you are very limited when it comes to relations between tables and such). Anyway, this is their website: http://satyan.github.io/sugar/
You can try using Firebase database for your chats. You Just need one line of code to enable chats offline persistence i.e
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
For more take a look on offline-capabilities.
Related
This is just a information question. I'm new to Android app development and currently I'm working on my first app and and it is ready for the release. Now I'm concerned about how to handle heap of users and where to save all their details my app is a service booking app so it needs to save all the order details products details and lots other stuff.
Currently I'm using cloud firestore to load and save all the data of app. But I'm having some issues like without authentication it won't allow users to access some of my data and other. I wonder how large apps save their data and load them perfectly.
I wish someone will help me how can I save all my app data and load them perfectly in app. And suggest me for a best way to manage large user base. And other stuff.
First of all, firestore is good option if you don't have complex backend logic on the database. For simple CRUD operations on data firestore is a good choice but as you said you have a bulk of data then you must go for the Backend database and then connect your database with Rest API. So that all your complex queries will be done on the backend and you can simply consume your API in the app.
If you have lots of data from different users, maybe you should use a central server(DB), something like Postgres or MySQL should work fine.
At the same time, you can also do some sort of caching to accelerate the fetching process, like create a small database locally(you can use Room) to store some user specific data.
I am trying to make a tutorial app with the help of Android, but I am confused where I should put the whole content (topic details). Actually I want to use it with the help of SQLite database. I used hashmap in my app.
if you really want to store your data on app, then SQL is best option. Otherwise you can use Remote server to store data. and SQLite for offline access to already viewed data.
I have a listview having three fields , but I don't know how to save my listview in android and fetch it back when user open app and display it.
I want to show the data saved in listview and I have to save the new data which user enter into my listview.
I would recommend having some sort of database on a server that would save that information and that you would need to pull that information from the database to display it in the app. However, android also has something called a sharedpref that allows you to save stuff in the app when the app is closed. The link is below. However this is not the best way a database would be, but it may work for your needs.
http://developer.android.com/reference/android/content/SharedPreferences.html
As per your requirment, there is no direct way to store list view, but you can store the data in the list view and you can set it in to the ListView later, for that you have to use Sqlite Database, refer official documentation of sqlite here, also check out this example.
read this example too (ListView of Data from SQLiteDatabase )
It depends on the purpose and the requirements of your app. If you are developing an offline app, then you should save the data entered in the listview.
Again, there are multiple ways to have the user enter the data. You could use a FAB(floating action bar) or have a text box in the last listview item.
Once the user has entered the data, you should save it to the sqlite database in a background thread and call notifyDatasetChanged() method on the listview adapter for the changes to reflect on the view.
If you have to send it across the network to store it in your server, you should do the networking on the background thread using a AysncTask or Handler thread model, or use libraries like volley or picasso to make it easy.
Hope this helped!
PS: Use ViewHolder pattern to improve performance in a ListView. Or there is RecyclerView from Android 5.0.
In Twitter Android App, Once the listview is populated with tweets/items downloaded from server, it never again talks to server to fetch them again. Even if you kill the app and start it again, it still retrieves the same old data.How does twitter store this much of data. Is it using database, storing all downloaded data in a file or caching.
In my app , i have a similar requirement.For now i store the downloaded listview data in a file and then read it whenever the app is started afresh.Is there a better approach or a followed patter for this.
Thank You.
There are three ways to save/persist data on clientside. These being:
SharedPreferences (not ideal with requirements)
File I/O
SQLLite database
As far as I know there isn't a big difference is performance between file-I/O and SQLLite. But SQLLite has a lot of other advantages.
You can query the database, this is more easy then writing it yourself with file-I/O
Manipulation of data is for more easy and less painful (delete/update records etc)
Supports relations between data!
Bottom line, go for SQLLite, it seems more work to setup but you will benefit from this in the future.
I'm creating a chat application and I need a little bit of guidance. I am using a sqlite database to store the chat as it comes in. I want my Activity, when it's open, to load the chat history from that particular chat and to continue to refresh as new chat is entered (my main question is how do I go about doing this).
Should I use a CursorAdapter with an inital cursor of a query containing the chat for that conversation and set it as the adapter for the ListView? I have tried this, but the data doesn't refresh when I insert into the database.
I know I didn't provide any code, but general conversation about what the best way is to go about this is welcome. Thanks!
Let me also mention that I need this to work for android 2.3.3 (API 10) and up (CursorLoader and all that is not available until API 11 which I did read a little about). The other thing I can do is use an ArrayAdapter and add chats directly into that (if the activity is open) and also insert it into the db in case it is not and then on onResume(), clear the ArrayAdapter and query all the convo once and readd each. Would this be the most optimal way?
Have a look at LoaderManager. Really simple and does exactly what you want.
It is available for 2.3.3 using the compatibility library.
http://developer.android.com/reference/android/app/LoaderManager.html