Sharedpreferences - Android Training

Sharedpreferences - Android Training  


Android assigns many methods of storing data of an application. One of this method 
is known as Shared Preferences. Shared Preferences allow you to save and retrieve
 data in the form of key,value pair.Shared Preferences is one of the ways to store 
data persistently in Android application. Here the data is stored in Key-Value pair. 
It is simple and easy to device differentiate to other data storage options like sq lite
 database where we need to write lot of codes.
Android Training in Chandigarh
In Shared Preferences the data is stored persistently, It means the stored data will
 remain even when the app is closed and removed from background. The data will 
be free if the app is uninstalled or if the user manually free the app cache from settings.
In order to use shared preferences, you have to call a method getSharedPreferences()
 that returns a SharedPreference instance pointing to the file that contains the values 
of preferences. Shared Preference are used to store the data for application 
in Android Training in Chandigarh.

We have three APIs to access preferences:

  • getPreferences() : used from inside your Activity, to approach activity-specific 
preferences
  • getSharedPreferences() : used from inside your Activity to access application-
level preferences
  • getDefaultSharedPreferences() : This used for the PreferenceManager  to 
get the shared preferences that work in show  with Android global preference framework.
Operating Modes :
  • MODE_PRIVATE: the ordinary mode, where the created file can only be 
approached by the profession application
  • MODE_WORLD_READABLE: Any application can read the preference data.
  • MODE_MULTI_PROCESS: This method will check for modification of 
preferences even if the Shared Preference instance has already been loaded
  • MODE_APPEND: This will attach the current preferences with the previously 
persist preferences
  • MODE_ENABLE_WRITE_AHEAD_LOGGING: Database open flag. When it is 
set, it would enable write ahead logging by default.
  • MODE_WORLD_WRITEABLE: Any application can edit the preference data. 
This may cause security holes in applications


Android Preferences provide a way to store user and application data in device. 
It stores primitive data including String objects in key-value pairs in 
 Android Training in Chandigarh.
There are various methods to store data in android :
  1. Preferences(Shared and User) : Store private primitive data in key-value pairs.
  2. Internal Storage : Store private data on the device memory.
  3. External Storage : Store public data on the shared external storage.
  4. SQLite database : Stock structured data in a private database. 
  5. Content Provider : Share data with other apps Shared Preferences
Shared Preferences(Permanent Storage):
  • Very simple way of share small amount of data between activities. Also for 
saving the state of the app. Preferences can stocks only primitive kinds of data.
  • Preferences can be private or public (world readable, writeable)(deprecated from Api 17)
  • To get SharedPreferences, use
  • – getSharedPreferences(String name) (if multiple pref. files)
  • – getPreferences() (if only one pref. File is needed)
  • To write values, call edit() to get SharedPreferences.Editor to be used when adding 
values to file.

Learn more about Android shared Element go through this link :- https://goo.gl/e4cte2

What is SOAP?

What is SOAP?

SOAP is a protocol designation for shuffle structured information in the application 

of Web Services in computer networks. It depends on Extensible Markup Language 

(XML) for its message format, and normally depend on other Application Layer 

protocols, most notably Hypertext Transfer Protocol (HTTP) and Simple Mail

 Transfer Protocol (SMTP), for information agreement and transmission.

Consuming SOAP web services from Android

Though SOAP based web-services are limited in these days, but there are lots of 

old companies whose web-services are still SOAP-based. If anyone wants to consume

 those services from Android, it is very important to know the procedure of consuming 

SOAP-based webservice.

Now, we will learn how to consume SOAP web services from Android. Before starting 

code, we have to collect some information:

  • SOAP_ACTION

  • METHOD_NAME

  • NAMESPACE

  • URL

  • Parameter List

  • Request XML/ SOAP_BODY/ 

    SOAP_MESSAGE (for Nested Parameters and Multiple Namespaces)

Now, the question is how can we get these information? if your client or service 

provider give you all the information, you won’t need anything and know more 

about Android Training in Chandigarh.

Android Training in Chadigarh

 

How it works?

URL: It is the url of WSDL file.
NAMESPACE: The targetNamespace in WSDL.
METHOD_NAME: It is the method name in web service. We can have several 
methods.
SOAP_ACTION: NAMESPACE + METHOD_NAME.
You can obtain above details by reading WSDL file of web service.
The soap web service that we are going used in this example have only one 
method that takes a number as parameter and find its square.

How to call soap web service?

  • First create request object of SoapObject class.
  • Now add information to request object that you want to send to web service.
 This is done using PropertyInfo class.
  • Create soap envelope using SoapSerializationEnvelope class.
  • Assign request object to envelope using setOutputSoapObject().
  • Create object of HttpTransportSE() class. Using this object call the
 soap web service.
  • We can get return from web service by using getResponse() method 
of SoapSerializationEnvelope class. The response is gathered into SoapPrimitive  
reference variable.

Learn Android Training in Chandigarh provided by CBitss Technologies.

Gson - Android Training in Chandigarh

What is Gson?

Gson is a Java library that is used to convert Java Objects into their JSON sketch. It 
can also be used to convert a JSON string to an comparable Java object.

Gson is an Open Source project, Gson can work with irrational . Java objects 
including previous objects that you do not have source-code . Gson provides several 
built in sertilize and deserializers. A serializer allows to convert a Json string to analogue 
Java type and a deserializers allows to follower from Java to a JSON sketch . We can 
also configure Gson to use custom delegations of your objects.

Android Training in Chandigarh

Gson allows to serialize a  complications of objects of the same type. As the universal 
information is continue in the JSON you need to define the type to which you want to
 serialize too. For this you have different options.

To use Gson in a Gradle build, add compile 'com.google.code.gson:gson:2.6.2' or 
a later version as addiction to your build.gradl e build file. Learn Gson with  
Android Training in Chandigarh.

Excluding fields from serialization and deserialization

By default, Gson shot to map all territory in the Java object to the JSON file it organise and 
vice versa. Gson allows to bind certain fields for serialization and deserialization. GSon can 
used for not serialize Java Beans, as the IProperty Change Support field lead to an 
infinite loop. Therefore you must ignore such a field from the JSON alteration.
To eliminate fields you have four options:
  • Use the short-term keyword on your garden to indicate that this field not not be
 serialized.
Android Training in Chandigarh

  • You can register a custom discharge strategy with the Gson architecture and its set
planning method. For this you would device the Exclusion Strategy and its hould Skip Field 
and should Skip Class(Class) methods.
  • You can define a custom vocabulary and tell GSon to ignore such fields.


Android Training is  Provided by CBitss Technologies they Provides 
 Android Training in Chandigarh Sector 34 works on the live projects, Students develops
 their own application projects.

SharedPreferences & Its Uses

What are SharedPreferences?

SharedPreferences are key-value group of general data types that are saved in a folder  
within an apps file structure. You can access this file from any place within the app to 
either put data into the file or take data out of the file. You can’t access the file from 
another app so it is secure from that point of view.
Android Training in Chandigarh

Where would you use SharedPreferences?

You would for example use SharedPreferences in a game where you would save the
 user’s name, high score, and state of the game when they logged off. Then the next time 
they log in, their score and game level would be recover from the desire file and they will 
continue the game from where they ended it when they logged off.

Save your data in a single or multiple SharedPreferences files

You can save your desire data in a single file or multiple files, based on your needs. The 
process is the same object for the SharedPreferences object that you get.In the case of a
 single file, call getPreferences() to get a SharedPreferences object and for multiple files, 
call getSharedPreferences() and pass it a name for the file as a parameter.
  • getPreferences() - for Activity level preferences. Each action will have its own 
preference file
  • getSharedPreferences() - for application-level preferences. You can access to 
 preference file from anywhere in the application

Android Training in Chandigarh
 

Retrieving the data

Once you have the SharedPreferences object, you can use a number of get<type> method 
for restore the values.

Uses of Preference share

A Shared Preference file is a simple XML file which prefer your application. You can store
 key-value pairs of data which your app requires often.

Most often, it can be used as some sort of cache/cookie which will be useful when the
 user's detail/action is to be retained when he comes back to use the application.

Some of the common uses of shared preferences :


1. If any user wants to  use shared preferences to check login, and if the user is logged in
 to your application you can direct that to the dashboard and if not, show them the login
 page.

2. Show the first time users the demo of your app. Most of the apps today shows the users 
who opens the app for the first time about the app, how to use it and what is where kind 
of things.

3. Some information which is required across different activities and it is hard to pass 
through design and not important enough to store in DB.

Shared preference are mostly for temporary storage in Android . We are 
providing Android Training in Chandigarh at CBitss Technologies, Practical training 
education assured.

Firebase Database

          Firebase Database


Android is developed by the Open Handset Alliance, which is 
Conducted by Google.An Android device is a device that runs 
on the Android operating system. Android is an array of software 
intended for mobile devices that features an operating system, 
core applications and middleware. An Android device may be a
 smartphone, tablet PC, ebook reader or some kind of mobile 
device that requires an OS.

Android is developed by the Open Handset Alliance, which is 
guide by Google. Some of the well-known Android device producers
 contain Acer, HTC, Samsung, LG, Sony Ericsson and Motorola.
Today has a huge demand of Android and now we will discuss 
the Firebase Database in Android with the Android Training 
in Chandigarh.

Android Training in Chandigarh

 Firebase Database in Android:

Firebase Real time database is a cloud hosted database 
that carry different platforms Android, iOS and Web. All the 
data is stored in JSON format and any improvement in data, 
return directly by executing a sync over all the platforms & devices. 
This qualify us to construct more pliable real time apps comfortably 
with minimal effort.
This article covers basics integration of firebase real time 
database. The other concepts like execute CRUD performance, 
data validations, firebase entrance rules also smother. If you are 
continue to firebase, advice you notice my different objects about 
Firebase Auth and Firebase Analytics to upgrade your knowledge 
over firebase.

Configure Firebase Database Rules:

The Real time Database gives a protect rules language that 
grant you to define how your data should be structured. By 
default, read and write entrance to your database is restricted
so hardly authenticated users can read or write data. To 
obtain started without setting up Authentication, you can 
configure your rules for public access. This does assemble 
your database open to anyone, even people not using your 
app, so be convinced to control your database again when 
you set up authentication.

Now we discuss the working of Firebase Database with the 
 Android Training in Chandigarh.

Working of Firebase Database:

The Firebase Realtime Database lets you build rich, 
collaborative applications by allowing secure access to the
database directly from client-side code. Data is continue 
locally, and uniform while offline, real time events continue 
to fire, giving the end user a responsive experience. When 
the device retrieve link, the Realtime Database synchronizes 
the local data changes with the remote updates that occurred 
while the client was offline, merging any conflicts
 automatically.
The Realtime Database is a NoSQL database and as such
has different optimizations and performance differentiate 
to a relational database. The Realtime Database API is 
designed to only allow operations that can be executed
 quickly.This enables you to build a great real time 
experience that can serve millions of users without 
compromising on responsiveness. Because of this, it is 
important to think about how users need to access your data
 and then structure it accordingly.
For More Information Click Here:- https://goo.gl/uNSy6N