Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday 22 March 2016

Activity lifecycle


An activity represents a single screen with a user interface the other words activity is a visible screen.

Mostly activity lifecycle containing more methods.




Descrption of all lifecycle methods          


onCreate() -> This is the first callback and called when the activity is first created.

onStart()  -> This callback is called when the activity becomes visible to the user.

onResume() -> Called when the activity starts interacting with the user

onPause()  -> Called when the current activity is being paused and the previous activity is being                                resumed

onStop()  -> This callback is called when the activity is no longer visible.

onDestroy()  ->This callback is called before the activity is destroyed by the system

onRestart() -> This callback is called when the activity restarts after stopping it.



ActivityMain.java 


 public class MainActivity extends Activity {
   String str = "Android Call : ";
   
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      Log.e(str, "onCreate() event");
   }

   /** Called when the activity is about to become visible. */
   @Override
   protected void onStart() {
      super.onStart();
      Log.d(str, "onStart() event");
   }

   /** Called when the activity has become visible. */
   @Override
   protected void onResume() {
      super.onResume();
      Log.d(str, "onResume() event");
   }

   /** Called when another activity is focus. */
   @Override
   protected void onPause() {
      super.onPause();
      Log.d(str, "onPause() event");
   }

   /** Called when the activity is no longer visible. */
   @Override
   protected void onStop() {
      super.onStop();
      Log.d(str, "onStop() event");
   }

   /** Called just before the activity is destroyed. */
   @Override
   public void onDestroy() {
      super.onDestroy();
      Log.d(str, "onDestroy() event");
   }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="I'm screen 1"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.samset.activitysample"
   android:versionCode="1"
   android:versionName="1.0" >
   
   <uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="22" />
   
   <application
       android:icon="@drawable/ic_launcher"
       android:label="@string/app_name"
       android:theme="@style/AppTheme" >
       
       <activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main" >
          
          <intent-filter>
             <action android:name="android.intent.action.MAIN" />
             <category android:name="android.intent.category.LAUNCHER"/>
          </intent-filter>
          
       </activity>
       
   </application>
</manifest>

Thank you





No comments:

Post a Comment