how to save rest web service data in android? - android

I am working on application, my requirements is when i post data as parameters like ID, Value etc using rest webservice and than i get some data as a response like deviceID, VendorID, driverID.
MY application senerio is. when user first time install app he/she can see the screen that enter the above data like ID, Value etc and some response appears that response is basically user configuration like deviceID, VendorID, driverID and has to save. And and than automatically move to the next screen using intent.
Now when user close app and than again open he/she will automatically move to list screen if he/she is login other wise stay on login. NO configuration screen at the, because its setting first time save in app (deviceID, VendorID, driverID).
How to save that configuration data of user first, which one is the best way.
Please give me best solution like in tutorial form and also little bit explenation.
Thanks

It depends a lot on what the "some response" is and how much data do you want to store.
In Android Storage Options:
http://developer.android.com/guide/topics/data/data-storage.html
There's Shared Preferences:
http://developer.android.com/reference/android/content/SharedPreferences.html
http://www.vogella.com/tutorials/AndroidFileBasedPersistence/article.html
How to use SharedPreferences in Android to store, fetch and edit values
Maintaining a database seems to be an optimal way.
You can store, update or over-write the data according to your need. The Id's can be maintained in tables, and further info with each Id can be associated in rows, increasing attributes and relating it with keys.
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
http://www.vogella.com/tutorials/AndroidSQLite/article.html
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

Related

How do I make a Login System in Android?

I am new to this site so I am sorry if there are any inaccuracies in this question. I am trying to create a login system using a local database. Previously I did some research on how to make a login system but still have no luck. I am using something like intent.putExtras() (sorry, not sure what the correct word for that is) to store user's details such as username, date of birth etc, so the following activity can receive the data from the previous activity. However, I just figured out that SharedPreferences is used by many people to implement a login system and I am planning on using it as I have an impression that it is more reliable (correct me if I am wrong). However, I have been implementing a login system using intent.putExtras() and never seen anyone implementing a login system that way. To make sure my current way of implementation is reliable, my question is, can I use intent.putExtras() instead of using SharedPreferences?
intent.putExtras(//something) only stores data in Bundle temporarily. You need to store the user info (or if user has logged in) somewhere, to be accessed next time you open the application.
intent.putExtras() are intended to be used, for example, when you want to pass data from one Activity to another.
Locally, sqlite and shared preferences are your only options.
My question is, can I use "intent.putExtras(//something)" instead of using SharedPreferences?
With what you want to achieve, no you can't.
After you edited your question:
If you only want to pass data then you can do so with intent.putExtras(), if you want to store data locally, then you will have to use sqlite or shared preferences.

Doubts in android

I've watched the Coursera android course and I have doubts how Android works in my application that I'm building. It does basic stuff, like register and show my info and do TODO using server as database. And I know it depends how I want to it begin built. Need some options.
Fragments can be built in ActionBar and whenever I want be called? Or is it bad to this way and stick with default menu built and hide it programmatically? Tried to google and didn't find any information.
The MainActivity is made to make http request POST to register name, email and password in my server. Is it possible to start the SecondActivity whenever he logged in? It's just like Instagram. But, I could set a condition to check depends if logged or not change the setContent(R.layout.main) or setContent(R.layout.second)?
When the register is done. All the data is saved on the server. But I want to check every time he changes activity or do some action if he's logged in or not. Could I use some thread with a flag(bool)? Could be a bad practice and reduce the performance? Or SharedPrefrences adding flag(bool)? But SharedPreferences are saved after the application is closed?
About to show my information in every Activity, like name, age and sex etc and such. Making request http just to show information is quite bad for my application, since it's just TODO app and I don't need to be connected to internet to see my info, but in case of edit, yes. So if I save in the SharedPreferences, but stays the same doubt, it will save after I close the application?
Since your question is likely to be drastically edited (as i advised in a comment) i quote the original text here.
Fragments can be built in ActionBar and whenever I want be called? Or
is it bad to this way and stick with default menu built and hide it
programmatically? Tried to google and didn't find any information.
Yes, fragments can be used whereever you like. But thats not really an answer.
Base your design on the various activities (think "what app screens should users navigate", and give these one fragment each.
The MainActivity is made to make http request POST to register name,
email and password in my server. Is it possible to start the
SecondActivity whenever he logged in? It's just like Instagram. But, I
could set a condition to check depends if logged or not change the
setContent(R.layout.main) or setContent(R.layout.second)?
Yes, you could have a LoginActivity that is called with startActivityForResult(). It would connect and return the success/failure. (See http://developer.android.com/training/basics/intents/result.html )
Also, keep in mind that HTTP POST is not encrypted, the password is sent as plain text.
When the register is done. All the data is saved on the server. But I
want to check every time he changes activity or do some action if he's
logged in or not. Could I use some thread with a flag(bool)? Could be
a bad practice and reduce the performance? Or SharedPrefrences adding
flag(bool)? But SharedPreferences are saved after the application is
closed?
Yes, SharedPreferences are stored after exiting the application. Ideal to simply implement app settings, but when storing lists of items you should look into other solutions. A JSON file may be of use, you could directly pull/push it from/to server.
About to show my information in every Activity, like name, age and sex
etc and such. Making request http is quite bad for my application,
since it's just TODO app and I don't need to be connected to internet
to see my info, but in case of edit, yes. So I saved in the
SharedPreferences, but stays the same doubt, it will save after I close the application?
See answer above. In short get a JSON string from the server, store it locally in a file. View and edit the local file, then upload it whenever you want. This way it works offline too, but can still download/upload the changes.

one time activity using sqlite

I understand how to create a one time activity that saves to preferences to make the activity appear only once. But can someone show me how to save the "first open" screen to sqlite. I want to prevent users from clearing the data and seeing the screen again.
to clarify
I am looking at a password login tutorial and i want the users to register a password with the app but once the password is set, I want the registration screen removed for security purposes. Can someone please help.
Thanks
Using SQLite as your storage is not going to help.
Android will store your database under /data/data/your.package.name/databases/yourfilename and thus, when a user clears the data for an app, it will remove any databases, along with shared preferences too.

Is it possible to show screen only once when app starts up?

I want to be able to prompt the users to enter the details required for the app only when it starts up for the first time (not other times). These details will be held in a database on the phone.
Would it be better to check the database each time or put these details in a shared preference? Furthermore, is this type of activity even possible on Android?
Depends on the details really. If it is a large amount of information you might consider using a Database. For just basic identification information, SharedPreferences should be fine.
If you do use a Database, you might consider loading them into your Application object. This would depend on how frequently you use this information in your app.
To check for the first start of the app, a SharedPreference is generally used AFAIK.
Use SharedPreferences or Database depending on the data complexity and its need later on..
Store a Flag in SharedPreferences and set this when user enters the data.
Check that shared preferences flag while on your first activity and redirects accordingly(to Details/one time page) if required.
here even if a user manually deletes data using Settings > Manage app > your app > clear data, Your app will know to get the details then from user....

Persist login/Authentication info on Android?

What is the best way to persist a users info in an android app? I have a login screen that uses a web service to authenticate the user and return basic user info.
I don't care about saving the username/password, but I do need things like a couple of integer ID fields (patientID and personID) and a first and last name.
I don't want the user to have to login every time they load the app. Someone suggested I use SQL lite to store the info, is this the best way or is there a more light weight solution?
Use SharedPreferences
refer this link also
Take a look at the answers and comments to this question: Android: Storing username and password?

Categories

Resources