0% found this document useful (0 votes)
61 views3 pages

Two Activities Example

This document contains code for an Android application with two activities. The FirstscreenActivity displays a button that, when clicked, launches the SecondscreenActivity using an intent. The code defines the two activities, their layouts defined in XML files, and the application manifest declaring both activities.

Uploaded by

Shyam Sunder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

Two Activities Example

This document contains code for an Android application with two activities. The FirstscreenActivity displays a button that, when clicked, launches the SecondscreenActivity using an intent. The code defines the two activities, their layouts defined in XML files, and the application manifest declaring both activities.

Uploaded by

Shyam Sunder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

FirstscreenActivity.

java
package com.example.twoactivities;
import
import
import
import
import
import

android.os.Bundle;
android.app.Activity;
android.content.Intent;
android.view.View;
android.view.View.OnClickListener;
android.widget.Button;

public class FirstscreenActivity extends Activity {


Button bt1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstscreen);
bt1=(Button)findViewById(R.id.button1);
bt1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent it=new
Intent(getApplicationContext(),Secondscreenactivity.class);
startActivity(it);
}
});
}
}

SecondscreenActivity.java
package com.example.twoactivities;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
public class Secondscreenactivity extends Activity {
Button button1;
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.secondscreen);
}
}

Firstscreen.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".FirstscreenActivity" >
<TextView
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Im First Activity Screen"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview1"
android:text="Click on this for second screen" />
</RelativeLayout>

Secondscreen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:layout_marginLeft="30dp"
android:text="Im Second Activity Screen"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.twoactivities"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.twoactivities.FirstscreenActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Secondscreenactivity" >
</activity>
</application>
</manifest>

You might also like