Android: most optimal way to save progress - android

My app lets users browse through slideshows of images. Every slideshow is a collection of all the images in a certain folder. Usually a folder has about 50-60 images. I want to save the image position in the slideshow the user is at when he/she exits that folder's slideshow. What would be the most optimal way for this?

You can save this persistently (across application launches by using a shared preferences).

You can use Gson to convert your class (which has your save data) into a json string and can use SharedPreferances to serialize the string into a file. When you want to laod your progress, you can read the SharedPreference value and load your class using Gson.

Related

How to save images by name as 1,2,3,....n in android

My app contains the camera functionality. I have develop the app.
As the app get starts one ListView of stations will popup(Like Station1, Station2,Station3....) & user has select one item from it. Then it will open the camera activity. So once the user took a picture, the image has to be stored like 'Station1_1', 'Station1_2', 'Station2_1', 'Station2_2' inside gallery. I have covered with the initial station name(Station1, station2..). But how do I store the last portion because it contains the sequence for each Station. So is there any way to save the images by 1,2,3....?
Thanks in advance.
There is a way but it isn't appropriate. If you just want to store each image having last portion is different then you can do in the following ways:-
You can call API for just handling counter.
You can store counter in PREFERENCE, but it won't work perfect if user clear data then new images were override old one.
You can store TIMESTAMP as end portion and it is appropriate way.

Save Image files and some text together as one file/object

I created an android test app with camera interface in which I want to save a text message and image file as one object. I am able to enter message, call the camera,take a picture and also populate the image in the image view on the app. Now I want to save them as one single record/object so that I can transfer it over network using protocol such as ftp. How to save image file and text together as one single file/object? Could someone please tell me how to do that. Thanks in advance.
There are lots of possibilities, and it depends to some extent on what will be consuming the file after it is transferred. You could, for instance, simply serialize the string and the image data using a DataOutputStream wrapped around a FileOutputStream. As a fancy version of that, you could define a class to contain the text and the image, have that class implement Serializable, and serialize it to a file. Alternatively, you could serialize the image data as a base-64 string and then put the text and the base-64 image data into an XML document or JSON string. Other approaches are also possible.
If you provide more details about what kind of process will consume this file after it has been transferred, perhaps we can provide more focused suggestions.

Android Save EditText with Image

Right now I have a simple App that takes a picture and saves it to a folder. I'm trying to figure out a way to have a user answer questions about each picture (I would just be using EditTexts with that). Is there a way to connect those EditTexts with the image so that when I would open up the image on another page that i could click a button to view the information that was entered along with that image? I have an idea on how to code everything else, just not keeping the edittexts associated with the image. Any ideas would be greatly appreciated!
Thank you!
perhaps you could create a data file alongside the image that has the same name as the image file, but a different extension.
So if you are saving an image called img1.png you save another file alongside it called img1.txt which contains the data you collect from the EditText(s). How you format this data file will depend a bit on how much data you have to store, and what kind of structure the data needs to represent (if any)
Then when you load up a png to display it you'll need to also load up the txt file that shares the same name, and populate the data contained inside to some TextView or something near your ImageView.
Use a database. Make a table that associates images with the data you want. When you display the picture, read the info for that picture from the database and display that as well. Either store the images directly in the db or store them in a folder and use the filename as the primary key in the database table.
There's number of ways to accomplish this. You could use a hashmap where the String is the data they entered and int is the resourceID of the image. For persistent storage, I recommend an SQLite Database that stores the string in a column and the associated image in another.
A few options:
Save a file with the image.. Give it the same name but .txt or something. The file should probably be stored in the location returned by getFilesDir() . Alternatively you could use SharedPreferences.
Use an sqlite database
Save within the exif data of the image. Use the ExifInterface class with setAttribute/getAttribute to save the values.

Array list of double in SharedPreference

I want to know whether it is possible to save as an array list of double in SharedPreference. In my application, I want the 'size' to be saved whenever there is new 'size' written from the user. It must be uploaded to an array list of double, without erasing the previous one.
first of all - the answer to your question is simple:
it's not possible.
but the good news are that there are lots of ways saving array of doubles (as you've been suggested in the comments):
save it to a binary file / serialized file in the internal/external storage, to SQLite database, make it the responsibility of the server side (if there is one..)
you can save the size of the array in the shared preferences if it helps you read the data from the file containing the serialized array, but I guess you already know that..
anyway - good luck

Keeping data when Android does an onExit()

I have a String array that I want to keep to display in a ListView, but every time I exit the activity, the global String array is deleted and the ListView doesn't display. Is there anyway that I can keep a String array in the application's storage for the next use?
It's actually pretty easy for just a string. You can store it in shared preferences. See this link: http://developer.android.com/guide/topics/data/data-storage.html#pref

Categories

Resources