Translate

Wednesday, 12 September 2012

Android Activity Life Cycle.

What is an Activity in Android?

              Activity  is one of the application component, which gives you platform to interact with widgets, views etc. Activity gives you user interface to do many task as per requirement. In application we can use many activities with different user interface and functionality. 
                   Now, we see how activity Life cycle works.


 Activity Life Cycle


Tuesday, 11 September 2012

Getting started with Android-Hello World

package my.hello.world;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class HelloWorldActivity extends Activity {
    /** Called when the activity is first created. */
    Button hello;
    TextView txt;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
       
        hello=(Button) findViewById(R.id.hello);
        txt=(TextView) findViewById(R.id.txt);
       
        hello.setOnClickListener(new OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
           
                txt.setText("Hello world");
               
            }
        });
             
     }
}



In above example we see that we used one TextView and one Button.
On the Button onclicklistener activity we simply set the Text as "Hello World" .