I am getting huge data from a database and I have to display the data in a table form. Please provide me a way to get the data from the web service and display it in a table.
You should get data from web and parse it then put all the data on map/list/arrays then create custom list according to your need then put this data structure in listview.
Your best bet is to actually use HTTP client or url connection with a buffer for reading to get the data (search on google for tutorials and examples). also be sure to set a larger timeout because you will be pulling a lot of data. then depending on the format of your data start parsing it, maybe store it in a database, Arraylist or something like that and then make a list with an adapter to show the data.
Url connection
hope this helps.
Related
Actually, I followed this YouTube tutorial and got an idea of delivering articles from a WordPress blog using the JSON API.
Here is the GITHUB link.
The above tutorial has a good example, but it only shows data from database only when there is no internet connection available. But I want the following:
Fetch data when the app is first started.
Store the data in the database
Set the adapter and show the data in the recyclerview
When the app is loaded for the second time check if internet is available and then check for new data, download if available, and then save the data into database and show the data in the recycler view.
Now, I've developed most of the logic for it, but the tutorial has used some advanced OOPs principles of JAVA which I am unable to fully comprehend.
Can anyone please help me and tell me how I can change the given code and display the data from database even if internet is available or not?
on MainActivity, line 91
if (getNetworkAvailability()) {
getFeed();
} else {
getFeedFromDatabase();
}
Above code will check network, and if network available, getFeed() which load feed from internet will be called. Just remove that case. I mean, remove above code, just keep the line
getFeedFromDatabase();
There is nothing complex, by the way. The idea is that you define your own interface which describe how to save data and implement it for database and for communication with Rest Api (Retrofit). There may be some differences between format of stored data (one form in database and the other on a server), so you have to convert it to format of your app.
For that you create another interface (see Repository pattern), which is also implemented by you db and web stuff.
When your have implementations for both sources you can choose which one to use.
I am building an android application in which I need to parse the data from the Database through JSON using Volley. I have 17,000+ rows in the table, I need to fetch all the row from the table via JSON and I need to store it in SQLite. Once downloaded the user can modify the fields of all row. Once the fields have been modified. The whole data need to be sent back to the server(Like synchronize).
What my problem is, If I attempt to download this huge data to my app. It's getting crashed. Is there any way that I can do to make this app work. Also tell me how to parse huge data from the server using volley.
I think it crashes because of timeOutError. When volley has to parse a large amount of data, you should set the timeout for your volley request. Default timeout is 2500ms, set it to 10000ms or higher it'll work for ex.
strReq.setRetryPolicy(new DefaultRetryPolicy(10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
It will not consume all the time that you allotted, but it will be disconnected once all the data is fetched
timeoutError will not give you crash, but onErrorResponse would be called, please make sure that tables that you are going to insert into were created before making insert operation.
1- Use Gson for parsing data and store in ormlite database.
2-After the modification to database tables you should be synchronize table row bye row using sync adapter to server.
3-Make Service for synchronize to server
I think you are getting OutOfMemoryException, am i right ?
Make paging for huge data, you can pull 100 by 100 or 1000 by 1000 from server,then you can store them in sqlite directly
Enable largheap in application manifest.
Use this link to know how to enable it
I am using retrofit to download large file.
Try to parse using jsonreader for large data.
I am not sure what type of server technology you are using. Downloading 17K + data and uploading the same amount overtime is I guess not the optimum use of technology.
Try some technology which reduces your burden about data sync and parsing. I am sure you are aware about Firebase by google. that one of the solution in this case.
Let me know if I misunderstood your question in this case.
On the server side I have a php script that connects to my mysql database and echo's string based on myurl.com/connection.php?id=22 where the 22 in the example obviously is the id for the string I want.
In my Android application I want to fill an arraylist with like 100 strings, but I am unsure how to do so, and what the best approach for doing it is.
As I understand I need to use asynctask to free the main thread from the process, and I have also looked at httpget although I am not sure if that is the only way of loading remote server content?
so from the my sql database the string values are returned ? right ?
the best way to do it is make the output from the server in json format and in your andriod app read the stream from the page and using json read fuctions and add the contents to your arralist using list . add() ; function...
I have local sqlite storage for my app. Once the user enables online sync option the data syncs with my online server using Asp.Net webservice. For syncing i am concatenating all tables' data in a single string and then passing that string parameter to service.
Example : "table_name1$col1_value$col2_value$col3_value|table_name2$col21_value$col22_value$col23_value.."
Its really hard to manage sync status of each row using this approach. And somehow it doesnt looks like a good approach to me.
The other approach i tried and looks better than this is to pass List of tablename1, List of tablename2 objects in a single containg object or as different parameters.
I am sending data in JSON format.
What approach should i follow to pass the data to webservice(any better approach than these two). A optimal and standardized approach for this.
Best approach is use a time stamp to handle this.
Initial request to server with time stamp value 0.
Server will give the all the data first time with Time-stamp.
Store the Time stamp to sharedpreferences.
In All next request pass the time stamp back to the server
Server will send only those data which are add/update/ after that
given time stamp
That is it.
My app pulls data from the web server. The results are given to a ListView.
Question 1: In what format should I transmit data to minimize data usage ?
Question 2: Should I use a SqlLite database to store the results from the server and feed it to the ListView or can I load it a few (say 100) values to the an ArrayList and set it as the data source for the ListView for a better performance ?
Question 1: In what format should I transmit data to minimize data usage ?
Answer 1: Its depends on your server side data format. If it is in Xml format then you have to
use xml parsing. If its in Json format then you have to use JSON parsing. I suggest to you use JSOn parsing.
Question 2: Should I use a SqlLite database to store the results from the server and feed it to the ListView or can I load it a few (say 100) values to the an ArrayList and set it as the data source for the ListView for a better performance ?
Answer 2 : You can use HashMap arraylist to store your data and retrieve as easily from it. But if you have a bunch of data earlier said by you then you need to use SQLITE database. In which you have to store your all data in it. and after that retrieve from the Database.
Q1: you can use JSON or Xml for data transferring because these both are standards but JSON is widely used for data driven applications.
Q2: For Large data you can directly load data to list using lazy loading technique, or this is totally dependent on a person, if you store in database to use this data on multiple locations and for data storage, this depends on you
Data format
The JavaScript Object Notation (JSON) is widely used in transferring data over the net
Storage
That depends on what you're trying to do - if the data is only temporary in nature, what you're suggesting works. If it needs to be stored across application starts, you will need some kind of persistence. A database would be one way to do that.
Remember though, that if you place your data loading code in your activity's onCreate or onResume method (or anywhere in startup callbacks of the activity lifecycle), it will get loaded everytime your activity is created - even if the user just flipped the device. If the data takes long to load (which over the network can always be the case, even if it's just a few bytes), this can result in very bad user experience.
One way to deal with this would be using a custom Loader, which can exist separate from your activity and would be able to cache your previously loaded data.
Conceptually, doing this would require you to extend Loader, and override the onStartLoading method to begin loading your data from the network. You should probably also override onStopLoading and onCancelLoad to keep your app from needlessly shoveling data over the connection even if it's not wanted anymore.
Having done this, you would provide LoaderCallbacks (as shown in the link I gave you), and instead of creating a new CursorLoader in the onCreateLoader callback, create an instance of your own custom loader class.