Social Icons

Pages

ADD

Thursday 23 April 2015

Explain Activity LifeCycle.

                                                    

1)onCreate()
                  Called when activity is first created.

2)onStart()
                   Called when Activity is visible to User.

3)onResume()
                     Called when activity will start interacting with user.

4)onPause()
                    Called when activity went to background but not be killed.

5)onStop()
                   Called when activity UI is not visisble to user.

6)onRestart()
                    Called activity  started again.

7)onDestroy()
                  Called before activity is destroyed.

Activity vs Fragment

Activity

1)Should have UI
2)Ability to retainState across Configuration Changed by using onRestoreInstanceState() and onSaveInstanceState().


Fragment(Introduced on 3.0)

1)Can have UI/NO UI.
2)Ability to retainState across Configuration Changed by using setRetainInstance(true).
3)ReUsability of UI
4)Tricky to handel back button.

Diffrence between service and intentServcie

Service 

1)Used to do the task in background
2)dont have UI
3)starts with main Thread.

Demerits:
 If we do long running task in background the ANR will occour,
To avoid this we have to use thread to do long running task in background
So to fulfill the above requirement we have intent service which provide worker Thread to do long running task in background.

IntentService

Its a extension of service which enable to do long running task in background

Diffrence between thread,asynchTask and service

Thread

1)Process in execution is called Thread.
2)We can create thread by using Extending Thread or Implementing Runnable.
3)Thread ,we can use if we don't want UI mainly(Otherwise if you want then you have to use Handler to update UI).

AsynchTask

1)Enable proper and easy use of UI thread.
2)It mainly used to update the UI when task has been completed.
3)It can be achieve by using the methods available in AsynchTask.


Service

1)It mainly used to do the task in background.
2)don't have UI.
3)Always starts from main thread.

Tell something about AsynchTask?

AsynchTask

1)It enable proper and easy use of UI thread.
2)It does the work in background and give the result on UI thread without use of Handler.
3)It has 4 stages
        i)onPreExecute()
                              Invoked before the task executed.
                              Runs in mainThread,

        ii)doInBackground()
                          Invoked in background to perform the task.
                          Runs in backgroundThread,

        iii)onProgressUpdate()
                          Invoked to update the progress UI after the call of onPublishProgress() in                                             doInBackground().

                          Runs in mainThread,
           
        iv)onPostExecute()
                        Invoked to update the UI finally
                        Runs in mainThread,

Diffrence between Thread and Asynch task?

Thread

1)Process in execution is called Thread.
2)We can create thread by using Extending Thread or Implementing Runnable.
3)Thread ,we can use if we don't want UI mainly(Otherwise if you want then you have to use Handler to update UI).

AsynchTask

1)Enable proper and easy use of UI thread.
2)It mainly used to update the UI when task has been completed.
3)It can be achieve by using the methods available in AsynchTask.

                                  

Monday 16 June 2014

Difference Between String and StringBuilder




String

String Builder 

1. String is Immutable type.

1. StringBuilder is mutable type.
2. Existing object cannot be modified rather creates new object in the String pool. 

2. Existing object can be modified and and doesn't create any new object in heap. 
3. String is Thread Safe.

3. StringBuilder is not Thread Safe.

4. Many Unused object left to be garbage collected if many String object are modified. 

4. Unused objects are not left to be garbage collected.