Saving array data collected by app to computer? - android

My app collects data which it stores in arrays, and I need to be able to access the data from outside the app. The tablet I am using has no SD card, so I'm thinking the best way to transfer data would be to save to 'external' system memory. I have found tutorials to save data on internal storage and for specific data types like pictures onto SD cards, but I can't figure out how to write an arbitrary file to an arbitrary location. Thanks.

This sounds like a perfect time to use a SQLite database. Android comes with SQLite support built in so its easy to set up. You can just create a database and store your array data there (you can even store pictures too as a byte[]). There are a number of tutorials that show how to do this. Here is 1 and 2. It should be pretty easy from there.

I'm not sure that you can write to an arbitrary place on the Android system. You could write to a file in /data/data// and then email that file to yourself.

Related

Approaches to storing data in Android

I have started learning Android development and I have a very newbie question. I understand that Android can store data in SQLite for example, but what other approaches are there to the storage of data within your application?
Do Android apps ever have data 'embedded' within the application, in which case what sort of data structure or concept would this use?
I am thinking of a scenario where the data is static but is perhaps not a large enough dataset to warrant a database..e.g. an app with general knowledge questions and answers
Any guidance much appreciated
Rowan
Yes You are correct You can use SqLite Database for storage
other ways to store data is SharedPreferences
But in your case you wanrted to save questions and answers which is static one so you can create a text file and put that in your assets folder and you can read that file as any other text file in java
Refer this link how to read file from assets folder
1.Sqlite Database
2.Shared preferences
3.Internal memory
4.external memory i.e sd card
i would suggest you to go with Database. as it will let you store as much data as your app needed, There are some other option also present like
Sharedpreference i.e. cookies in general term. It let u store only few KB data and not good to store much data. When u retrieve data from cookies. All data will be store into ram and use app memory. that is use less when u do not need all data to retrieve and store into ram and then remove
Store into file and ship that file with your app. Yeah. this could be better idea again. you need to read it byte by byte. and hence reading to mid or last line will store all data into ram and hence will take memory.
Use Web Service to download data. It will let you store Large data and you have to download using Web APi. Hence it could be better idea. But this requires active Internet connection to play game to run app.
There must be some other option also present. You can search. surely you will find them :)
Overall Database it good solution for all app. As it will let you do search store delete and let you do other operation in less amount of memory. In Mobile Development Memory is very Important thing we have to take care of.
Let me know if you have other unclear thought.
item
You could also store info in a server.
Pros :
You can change the content without needing user-side update of the app.
Cons :
Your app (mostly the UI) would need to manage connection problems.
You may need to implement async tasks for querying data from server.

Android Storing RSS feed parsed data in a database for offline use

I am parsing a Rss feed using sax parser in android. I am able to display the data online when net is connected but i also want it to work for offline use and update it when it gets connected again to internet / wifi. I have no clue how to go about it.
What should be my best approach now ? should i construct Sql database ? considering i have images as well.
Or there is any other simpler way. I would prefer simpler way.
I need some further suggestion on the Sql database approach here, First : My rss feeds gives image url links which i diplay using bitmap and insutstream at runtime but now for offline purpose i need to save complete images like whatsapp does right ? is this right ? if yes how to save complete images in database ? And last i want to save the complete database on sd card not in internal memory , storing data on sd card will work fine or it will create problem ? because whatsapp stores quite a data in internal memory !! if storing on sd card is not a problem how do i store complete data on sd card ?
This depends on how long you want the data to persist. Ask yourself:
Should this data be available to the users after rebooting the phone, or after force closing the app? Should it be available regardless of the last time I had connectivity, as up to date as possible given that?
In that case, then yes - you should use a database. Android has a number of built in helper classes for sqlite databases.
http://developer.android.com/training/basics/data-storage/databases.html
Which should get you started.
The images are pretty straight forward as you'll just stash a reference to the image(s) in the db. You would of course write these images to disk as well (on the sd card or some other place...) See:
Save bitmap to location
Your other options, afaik are:
1) SharedPreferences (not really suited to this).
2) Serializing your data and writing out/reading in from some file.
If you're still looking for more information on Database concepts and Android, here is a very good tutorial on the topic:
http://www.vogella.com/articles/AndroidSQLite/article.html
You can use droidQuery to download the RSS Feed and cache it. Working off of this gist, which expects you to use the android-rss library, you can add the following cache flags to your AjaxOptions object:
.cache(true).cacheTimeout(AjaxCache.TIMEOUT_NEVER)
This will make it so the response is cached until you explicitly call:
AjaxCache.sharedCache().clearCache();
Which you can do after the network is connected (for help on this, check out NetWatcher).
Note that using this cacheing mechanism allows a very simple solution that will only store as long as the app process is live. If you want to save across sessions - so that if the user opens the app later and is not online, you will want to use something more complex and long-lasting, such as SharedPreferences or SQLite. A good list of options can be found here.

Saving GPS points without database

Can I save GPS points in android without using database?
I want first to track user's position then to reverse his track, so I need to save tracked points in order to traverse them.
You can always write your data to a file, following whatever format suits you (XML, JSON, or your own custom-made format)
See Using internal storage and Using external storage guides.
Depending on the size of the resulting file, it might be better to use External storage, which often has more space.
Also, maybe you have some specific reasons to not use a database, but I think using SQLite is easier to manage than file for storing data. See Using database guide for more information

best away to save strings on android

What is the best way to save several strings on android?
I thought that the best way was SQLite, but in this case when I close my app the data will be save? When I open the app again the data will be there? Or should I use txt files to save it and restore it?
It depends on what you are trying to do with the file. You have several options when you are saving data: internal storage, external storage, caching, SQLite database, or networking. If you are just saving a couple Strings I think that creating a database is overkill. I would look at saving the files to internal storage. You can write the Strings to a file then retrieve that file when you restart the app.
You don't want to make things more complicated than they need to be. Keep it simple. If you are saving a couple KB worth of data, use a file. If you are getting into MB worth of data, and need to query specific data sets, then look at a database. You have to remember that databases take a lot of time and resources, not only to set up, but to maintain.
Here is the Android document that outlines the different ways to save data to a device: http://developer.android.com/guide/topics/data/data-storage.html
This should really help you understand what is going to be best for you.

Most efficient way to store and retrieve large amounts of text data in android

I wanna write an android application which will store and retrieve large amounts of text data. I wanna store text in paragraph wise.I need to manipulate this text data in an efficient way. What will be the best way for doing this?
I think the best way is to save all data inside a file. And save this file to specified location in sdcard. If you are saving data inside a file you will get same format as you saved(e.g Paragraph wise in your case).And you can delete file when ever you want.
I found this may this help you to solve your issue
SharedPreferences is apparently implemented internally as an XML file which is serialized and deserialized in full on update. And it's a Key-Value store with no index. So use that only for simple data associated with your app. Any more than 50 keys and you've probably overdone it.
ContentProvider is intended for sharing data across applications. You've explicitly said you don't want to do that.
SQLiteDatabase is intended for individual apps to store data, and provides a lot of flexibility to store and index data in different ways. I personally use it to store logs in one of my apps. I'd recommend that route.
See this discussion for more details

Categories

Resources