Saving information into file and load it on start? - android

Basicaly what im intrested in doing is when i give my app some GeoPoint i want to save i want it to save this to a file on the phone.. But i have no idea how i will do this saving, I need to save the longitude, latitude, and two strings for each object and when i make a save.. And this is for each point i want to save.. And this brings me how i will make the loading when the app starts.. Maybe i could make it save all information for each object on separate lines and it would be easier to load it?
I never had experience with saving and loading this is totaly new to me so how would i solve something like this?

You've asked a general question so the best I can do is give you a general answer. You'll want to do this reading and writing in your onCreate and onDestroy methods for your activities. For details on storing persistent data on the android phone, please read the android Data Storage article.

Related

What is the best way to save all high-scores of multiple levels in android?

I am writing a minesweeper application in android. It's got 3 difficulty modes and I want to save all the scores of all three difficulty modes. If I wanted to store just the high scores for all the modes, I could have done it with a SharedPreferences object but I want to store all the scores and display them to the player sorted by the time taken to solve or date on which it is solved.
I have thought of saving data in a file, or in a json file. I don't want to use SQLite databases because it's too much code.
I simply want to know if there is a better way to do this other than saving everything in a file (maybe in the assets).
There is a similar question but I don't think the accepted solution can be used to solve my problem.
You can use Firebase Database for that. The good thing with the database is that if you want your game to also display the leaderboards to others who are playing it, it shows in real-time. Simply add data when the game ends and filter the results based on the data. Hope this helped, heres a link to get you started here

Android:is it possible to share the bitmap image without saving it

I am creating bitmap image in my application and i dont want to save it on phone. If user want he can share it with other apps.I tried many things but m not able to share the image with other app without saving it. Is there really any way by which we can share the image with other android application without saving it? or we must have to save it first and then share. Kindly suggest.
The Bitmap saved is not on disk, but only in RAM. Other apps are not allowed to read your's app's allocated RAM. The ways for your app to export volatile data are:
Write byte data to a large Parcel, and put it in an Intent extra.
provide data over to a network socket or via a custom content/file provider etc.
But even for these methods to work, you need other apps to know how to fetch data. Which is very unlikely unless the other app is also programmed by you.

Save everything of an activity

I've got an activity and I want to keep everything inside it (Bitmaps, texts, buttons..) so when the user restarts the phone and clicks on my app, everything is like the last time he used it.
Any idea?
I've been reading about the lifecycle of an application in Android, and i know the basics theoretically but I don't know how to implement it.
Thank you.
Actually, you don't need to do anything on objects such as Buttons and TextViews, since they do not change during your Activity's lifetime. When your application restarts, they just get recreated and they look the same anytime. Things that you want to save are possibly user inputs or downloaded files. If you have any of these, then I'd recommend learning this post, it describes different data storage mechanisms in Android. For different kinds of data you'll need different solutions, for example text inputs can be saved in SharedPreferences, but bitmaps should probably be saved in the file system. Hope this helps.
Maybe it is not the best solution, but you can try SharedPreferences and save different user data into different variables upon exiting.
When the app is restarted, read the values stored in the SharedPreferences and display these values in your respective views.
Other than SharedPreferences, you can also try out these various options according to the type of data you would want to persist!

where is the best place to save game progress?

I'm developing a quiz game and I want to save the progress... Actually I use sharedsettings, is easy and fast, but the user can delete program files and lose the progress. Same happens with a database. I should use a file? I'm only interesting to save a boolean for each question: "correct answered or not?"
Thank you!!
SharedSettings. And you're already using it. It's very difficult to save a user from his/herself. If it's on the device then it can be destroyed either stupidly or maliciously. And don't forget that everything is a file and there's nothing you can put on the device that will be hack/idiot proof.
The only way to get around this would be to store user settings off the device via something like a web service (and backing database.) But I would say that if you're using SharedSettings... you're OK. Leave it at that. I would only consider using an app-specific db if you expect the number of question you track to grow to a very large size and want more control over the data.
Where in code logic?
In general, it's best to save any UI preferences at onPause. Android design wants you to never have a "save" button, rather save constantly.
As far as at each question, i guess you would save after answering each question?

Caching images in android?

I'm currently building an android application, and I'm making some HttpRequests to grab images from an API. Right now I'm just storing them in an object container, and then storing them in ArrayLists, but I want to store it into a temporary cache for the application so that when I quit out of that particular activity and go back into the launcher activity, when I go back into that activity, I won't have to make another httprequest for the image.
However, I don't know where to start, what to read up on, or anything regarding temporary storage. I've only used SharedPreferences, and passing extras along intents. Can anyone point me to any good places to get started with, either documentation or sample code?
edit: I forgot to mention that I'd like the data to be deleted when I quit out of the application. I'm not too sure what caching even means, so I don't know if this happens by default when people talk about "caching"
You could refer to Android - How do I do a lazy load of images in ListView.
There are a cache example in Fedor's LazyList.zip from the answers.
The Activity class has some great information on cache directories and the Lifecycle. If your cache is more than a couple megabytes you should consider using external storage.

Categories

Resources