KIO
Kreative Ideen online
Activities

Activities

Activities are the unique screen pages in Android!

An activity is a single focused thing your user can do.If you chain multiple activities together to do something more complex, its called a task.

Activity = screen page + related code

package eu.kio.android.beeradvier;

//Make sure class extends the Android Activity class
import android.app.Activity;
import android.os.Bundle;

 //Make sure class extends the Android Activity class 
public class FindBeerActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        //This is the onCreate() method. It's called when the activity is first created
        super.onCreate(savedInstanceState);
        //setContentView() tells Android which layout the activity uses. In this case, its activity_find_beer. 
        setContentView(R.layout.activity_find_beer);
    }
}

The above code is all you need to create a basic activity. As you can see, it's a class that extends the android.app.Activity class, and implements an onCreate() method.
All actities have to extend the Avtivity class or one of its subclasses. The Activity class contains a bunch of methods that transform a Java class from plain Java into a full-fleged Android avtivity.

All activities also need to implement the onCreate() method. This method gets called when the avtivity object gets created, and it's used to perfomr basic setup such as what layout the avtivity is associated with. This is done via the setContentView() method. In the example above, setContentView(R.layout.avtivity_find_beer) tells Android that this avtivity uses avtivity_find_beer as its layout.

Leave a Reply

Your email address will not be published. Required fields are marked *