android tutorial - Activity in Android Activity | Developer android - android app development - android studio - android app developement
Activity
package com.example.android.activity;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
click below button to copy code from our android learning website - android tutorial - team
- NOTE Activity must be declared in AndroidManifest.xml before using it.
E.g:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
click below button to copy code from our android learning website - android tutorial - team
Layout file example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent">
//Add other views here
</LinearLayout>