Simple Access w\Read&Write to XML file using Android - android

I'm new to android development, and I'm trying to work a very simple database solution. I have a max of five variables I want to store when the app is installed, and I want the user to be able to change these variables and their changes be remembered after they've closed the app. While I could use the built in SQLite feature, that's way more complex than I need.
Normally in other languages, like VB, C#, and Javascript, I just load the XML into an XML object and then navigate the nodes. Is there any way to do that in android? This solution should only be a dozen or so lines of code within a single class.
If this isn't possible, what is the simplest way to store and retrieve simple data?

This is a common question and of course there is a way. Use Simple XML. I wrote a blog post on how to make that happen.
Essentially the Simple XML library lets you marshal and un-marshal XML to and from Java Classes by correctly annotating them with Simple XML Annotations. Just read the simple tutorial and my blog post to understand what I mean.

Related

how to read a java object from android resources

I am still new to android and there is probably an obvious answer to my problem. But I have not found the correct question to ask or google for.
What I want to do is read in a xml representation of a (list of) java object(s) and have the objects accessible from my activity.
Is this possible with android resources?
After some reading through the internets the best solution I found was to write the objects as json string and save them in res/values.
And then use something like Gson to parse them as java objects.
But there has to be a better way.
What would be the standard way to approach this?
To add some context: I am programming a small android game and would like to have a research-tree.
Each research item has properties like a name, costs, effects and of course a list of references to other research items as preconditions.
I would appreciate any ideas and suggestions.
If you don't want to use 3rd party solutions, the recommended way is to use the platform's XmlPullParser:
https://developer.android.com/training/basics/network-ops/xml.html

Reusing code between Android and Google App Engine

I'm new to GAE, but have worked on Android for a while now. I'd like to write some code that basically parses xml files and stores it on a database at the backend. Then send part of this data based on a query to the front-end android app.
The android app in turn will store the data in the local database. Here, if possible, I would like to reuse code from the GAE and the Android app. So, my questions are:
what are the choices for databases on GAE?
which methodology to use to promote code reuse with backend and frontend?
is there any xml parser which can also be reused?
Thanks,
Rajath
in GAE basically you have two non exclusive choiches: The Google Cloud SQL and the Datastore.
Which is better and which to use it depends on your application. The SQL server is a classical mySQL base database while the Datastore is based on a different non-relational structure and you should take some time to get familiar with it.
Generally speaking you can reuse code being in both cases Java, however there are many cases in which you interface with different services (ex. a local android sql service rather than the google datastore) therefore in this cases you have to adapt your classes. I can suggest in these cases to reuse concepts rather than code, let me explain: imagine you have to manage images. you take a picture in android and you have to associate to it some informations, for this purpose you can define a custom data model (let say a class AppImage). AppImage will contains only data and basic methods. Then you can for example create a class that manages AppImages (ImagesManager) (implementing upload, local storage and so on). In the serverside tyou will have a similar structure with that can differ for the persistency technologies. Therefore you can again create a similar object AppImage and also a class that manages them (ImagesManager). What will be different in the code will be the API calls to store info and in these cases you have no choiche and you have to write custom code, however the high level structure remains the same and this may help when things start getting complex.
The comment above worth also for the xml parsing problem. (What libraries are there for processing XML on Google App Engine/Java Servlet)

Is It possible to read serialization data in android which made by iphone development

I have one file which is create in iPhone using serialization object. and i want to do read in android. Is it possible or not? please reply fast in advance thanks
I am assuming that the serialized data is in a pList.
See this http://code.google.com/p/plist/
You should be able to read any file generated by another language. It's better if there's a library out there for it. It'll get complicated if the file uses arrays, especially dynamic ones. This may require some fun time with a hex editor. I can't guarantee reliability with this method though if the data isn't simple. Just realize that this may end up being a tricky task
It's better to have a file spec made. You don't have to use a binary file, as you can use something like JSON or XML if it's all text-based information.

Easiest way to store a list a my own class in a android app?

What is the best/easiest way to store a list (LinkedList) of a class which I created in an Android application?
In apps in other plattform it could be done using:
a ORM framework
the database
serilization and store the file
But my question is: Which of those 3 is the easiest to implement it in an Android application without using a lot of time to make this code?
Using directly SQLite in my opinion is the easiest and most straightforward way to do it. I would consider an ORM-Framework only if I have a lot of classes to store. But I am assuming that's not your case.
Straight serialization to a file might be a good idea, but I would prefer SQLite to have the possibility of using database versions, adding indexes and performing more complex search on the data easily.
It depends on how you inted to use this data. Simplest way is inherit you class from Serializable and dump LinkedList to a file. This works great if you don't need random access to elements of this list.
SQLite is good and flexible but it requires much more coding effort.

Android Database

I am new to android. I am creating ToDoTasks application in android. i have crated Gui of the application and it is working perfectly. I am able to add tasks in it. Now i want to know that i want to save 'task list' in an area so that every time user comes on it , than it should maintain the list of previous tasks which were added in it. What is the best way to do this ?
Whether i should go for database in android or is there any other way to do this ?
Please suggest me. Please don't mind , i know this is a silly question but i have no other way to solve it.....
You have multiple options with varying degree of complexity.
Do you foresee sharing your todolist with another application. If yes then you need to host your data as a content provider.But I digress.
The most simplest option is Shared Preferences. The api is very simple to use and you do not need to write a whole lot of plumbing code. You can directly store an list of string in the shared preference of your activity.
The more elaborate solution is using sqllite. If you foresee your domain model to become more complex than just a list of strings, then you should see if the additional complexity is worth it.
Look here for more details. (I will not worry about the file options, the other two mentioned here are superior to that solution)
You can use sqlLite db for android. See this or this for example.
Here is another example of an SQLite implementation:
http://p-xr.com/android-tutorial-simple-but-persistent-data-storage/

Categories

Resources