Showing posts from September, 2012

Hibernate Architecture

Hibernate Architecture:




it provides access to the info about telephony services.
we can register services to receive notification of telephony state changes.



public int getCallState()-    get the call state

public cellLocation getCellLocation()- returns current location of the device.. returns null if the current location not available.

this requires permission in the manifest file.

what permissions we need to declare:


some more methods:

we can get device id

public string getDeviceId()

we can get network operator

public string getNetworkOperator()

we can get sim operator name

public string getSimOperatorName()

Hibernate Introduction

WifiManager in Android




WifiManager class provides primary api for managing all aspects of wifi connectivity.

get the instance of this class by calling


it deals with list of configured networks. this can be viewed, updated.

check wifi status:

ConnectivityManager conMgr;
NetworkInfo netInfo;
WifiManager wifiMgr;

//wifi  enabled
//wifi disabled i.e not available

Services And BroadcastReceivers in Android

Activity: it is single screen application. it is a foreground contain user interaction.
Service:a service is a component which runs in the background without interacting with user.

Android provides many predefined services exposed via Manager class.

Own services must be declared in the manifest file..

Some methods:

An activity can start a service via startService() method.

stop the service by using stopService() method.

bindService() - this is for activity to interact with service.

it needs "ServiceConnection" object.

Once service is started    onCreate()  is called.

onBind()- the system calls when other component want to bind the service.

onStop() - for stopping the service.

OnDestroy()- called when service is no longer used. and it is destroyed.ex: package com.example.serviceexample;
import android.os.Bundle;import;import android.content.Intent;import android.view.Menu;import android.view.View;import android.view.View.OnClickLi…

Data Storage in Android

Data Storage:
Android stores data in 5 ways depends on the data storage

internal storage
external storage
sqlite database
network connection

sharedpreferences: it will store the data as a key value pairs

to get SharedPreferences of ur app, use these

getSharedPreferences()  - use this if u need multiple preferences

getPreferences()- use this if u need single preference.

you can find shared preferences example here

Internal Storage:

InputStream()- for reading the data
OutputStream()- for writing the data to the stream

1.openFileOutput() - we call the particular file.

2. write to the file with  write()
3. close the file after writing -   close()

String FILENAME= "hello_file";
Strig string="helloworld";

FileOutputStream fos=openFileOutput(FILENAME, Context.MODE_PRIVATE);



getDir()- create directory in the internal storage

deleteFile()- deletes the di…

Activity Life Cycle

Activities in the life cycle are managed as an activity stack. When a new activity is started, it is placed on the top of the stack. It becomes the running activity.The previous activity always remains below it in the stack, and will not come to the foreground until the new activity exits.4Stages of Activity:1.If an activity in the foreground of the screen (at the top of the stack), it is active or running.If an activity has lost focus but is still visible, it is paused. It saves the activity state, but can be killed by the system in extreme low memory situations.If an activity is completely occupied by another activity, it is stopped. It retains all state and member information.If an activity is paused or stopped, the system can drop the activity from memory by either asking it to finish or simply killing the process.

Public class MainActivity extends Activity {Public void onCreate(Bundle savedInstanceState) {Super.onCreate(savedInstanceState);…