This blog begins by showing you to create an activity. To create an activity , you create a Java class that extends the Activity base class :
public class MainActivity extends AppcompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.laout.activity_main);
}
}
Your activity class loads its user interface ( UI ) component using the XML file defined in your res/layout folder . In this example , you would load the UI from the main.xml file :
setContentView(R.layout.activity_main);
Every activity you have in your application must be declared in your AndroidManifest.xml file , like this :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android package="com.jfdimarzio.hellworld">
<application
android:allBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filer>
</activity>
</application>
</maifest>
The Activity base class defines a series of events that govern the life cycle of an activity . Figure shows the lifecycle of an Activity.
The Activity class defines the following events:
show the life cycle of an activity and the various is goes through - from when the activity is started until it ends.
The best way to understand the various stages of an activity is to create a new project , implement the various events , and then subject the activity to various user interactions.
public class MainActivity extends AppcompatActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.laout.activity_main);
}
}
Your activity class loads its user interface ( UI ) component using the XML file defined in your res/layout folder . In this example , you would load the UI from the main.xml file :
setContentView(R.layout.activity_main);
Every activity you have in your application must be declared in your AndroidManifest.xml file , like this :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android package="com.jfdimarzio.hellworld">
<application
android:allBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filer>
</activity>
</application>
</maifest>
The Activity base class defines a series of events that govern the life cycle of an activity . Figure shows the lifecycle of an Activity.
The Activity class defines the following events:
- onCreate( ) - Called when the activity is first created
- onStart( ) - 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( ) - Called when the activity is no longer visible to the user
- onDestroy( ) - Called before the activity is destroyed by the system ( either manually or by the system to conserve memory )
- onRestart( ) - Called when the activity has been stopped and is restarting again.
show the life cycle of an activity and the various is goes through - from when the activity is started until it ends.
The best way to understand the various stages of an activity is to create a new project , implement the various events , and then subject the activity to various user interactions.
Comments
Post a Comment