Tuesday, 5 March 2013

activity life cycle

there are 7 methods in activity life cycle below are listed:
1)oncreate
2)onstart
3)onresume
4)onpause
5)onstop
6)onrestart
7)ondestroy
 actual life cycle of an activity shown the figure above:
The following code will be helpful  for shows the life cycle of an activity:

package com.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class LifecycleActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Toast.makeText(this, "oncreate", 15).show();
    }
    @Override
    protected void onStart() {
    // TODO Auto-generated method stub
    super.onStart();
    Toast.makeText(this, "onstart", 15).show();
    
    }
    @Override
    protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
    Toast.makeText(this, "onresume", 15).show();
    
    }
    @Override
    protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    Toast.makeText(this, "onpause", 15).show();
    
    }
    @Override
    protected void onStop() {
    // TODO Auto-generated method stub
    super.onStop(); 
    Toast.makeText(this, "onstop", 15).show();
    
    }
    @Override
    protected void onRestart() {
    // TODO Auto-generated method stub
    super.onRestart();
    Toast.makeText(this, "onrestart", 15).show();
    }
    @Override
    protected void onDestroy() {
    // TODO Auto-generated method stub
    super.onDestroy();
    Toast.makeText(this, "ondestroy", 15).show();
    
    }
}














No comments:

Post a Comment