Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Monday, 4 April 2016

What is Activity



Activity

An activity represents a single screen with a user interface just like window or frame of Java.Android activity is the subclass of ContextThemeWrapper class

Activity lifecycle

Activity is containing many method that use in development of android project.



    

                                              

onCreate :This is the first callback and called when the activity is first created

onStart :This method called when activity is becoming visible to the user.

onResume :This method called when activity will start interacting with the user.

onPause :
The paused activity does not receive user input and cannot execute any code and called when the current activity is being paused and the previous activity is being resumed.

onStop : This method called when activity is no longer visible to the user.

onRestart :This method called after your activity is stopped, prior to start.

onDestroy :This callback is called when the activity restarts after stopping it.

See below example how to use this methods..


package com.samset.activitysample;  
import android.os.Bundle;  
import android.app.Activity;  
import android.util.Log;  
import android.view.Menu;  

public class MainActivity extends Activity {  
 private String TAG="ActivitySample";
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.activity_main);  
        Log.d(TAG,"onCreate method  invoked");  
    }  
    @Override  
    protected void onStart() {  
        super.onStart();  
         Log.d(TAG,"onStart method  invoked");  
    }  
    @Override  
    protected void onResume() {  
        super.onResume();  
         Log.d(TAG,"onResume method  invoked");  
    }  
    @Override  
    protected void onPause() {  
        super.onPause();  
         Log.d(TAG,"onPause method  invoked");  
    }  
   @Override  
  protected void onStop() {  
       super.onStop();  
         Log.d(TAG,"onStop method  invoked");  
    }  
       @Override  
    protected void onRestart() {  
        super.onRestart();  
         Log.d(TAG,"onRestart method  invoked");  
    }     
    @Override  
    protected void onDestroy() {  
        super.onDestroy();  
         Log.d(TAG,"onDestroy method invoked");  
    }  
}  



I hope this is very helps you
Thank you                                                                                                                                         

No comments:

Post a Comment