Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accountmanager vs sharedpreference for authentication and server communication

In my project want to read and write the data in server depends upon the authentication key(user).

So far I planned to use shared preference to store user authentication key for further communication with server.

Later I came to know "Account manager" by reading this tutorial:

I have little confuse to use account manager or sharedpreference.

I feel little difficult to understand accountmanager.

Can any one guide which method suits for my project.

Any tutorial for account manager.?

Any other suggestions...?

Thanks in advance.

like image 542
Amir Avatar asked Oct 16 '14 06:10

Amir


People also ask

What is the difference of Sharedpreference to preference?

SharedPreferences ? Looks like they are for similar things - you can put and get a value by a key in both of them, but Preferences looks like something more difficult and belongs more to the OS than to an app.

What is use of Sharedpreference?

A SharedPreferences object points to a file containing key-value pairs and provides simple methods to read and write them. Each SharedPreferences file is managed by the framework and can be private or shared. This page shows you how to use the SharedPreferences APIs to store and retrieve simple values.

What is Android AccountManager?

android.accounts.AccountManager. This class provides access to a centralized registry of the user's online accounts. The user enters credentials (username and password) once per account, granting applications access to online resources with "one-click" approval.

Is Android account manager secure?

Using an AccountManager to store credentials is a much secure way than storing in a file or a SQL DB. A file can be retrieved by any other app unlike via AccountManager Android will enforce that only your app will be able to access to the key.


1 Answers

I would recommend you to think about your requirement first. If authentication is like google+, Facebook and Twitter then I would suggest you to use AccountManager

AccountManager: This centralized registry of user's online account. Account Manager is capable of storing the OAuth token and does the job for all Google Apps in Android.

SharedPreferences:This is for storing and retrieving small range of data for more this.

like image 181
Dilip Avatar answered Nov 15 '22 01:11

Dilip