Use intent to redirect between two activities

Source: Internet
Author: User
Use intent to redirect between two activities

 

Project directory

 

 

Androidmanifest. xml

 

<? XML version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: Android ="Http://schemas.android.com/apk/res/android"
Package = "gogler. myandroid"
Android: versioncode = "1"
Android: versionname = "1.0" type = "codeph" text = "/codeph">

<Uses-SDK Android: minsdkversion = "14"/>

<Application
Android: icon = "@ drawable/ic_launcher"
Android: Label = "@ string/app_name">
<Activity
Android: Label = "@ string/app_name"
Android: Name = ". activityintentactivity">
<Intent-filter>
<Action Android: Name = "android. Intent. Action. Main"/>

<Category Android: Name = "android. Intent. Category. launcher"/>
</Intent-filter>
</Activity>

<! -- Add the second activity -->
<Activity
Android: Label = "@ string/app_name"
Android: Name = ". secondactivity">
</Activity>

</Application>

</Manifest>

 

Activityintentactivity. Java

 

Package gogler. myandroid;

Import gogler. myandroid. R;
Import Android. App. activity;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;

public class activityintentactivity extends activity {
button Bt;
intent;
/** called when the activity is first created. */
@ override
Public void oncreate (bundle savedinstancestate) {
super. oncreate (savedinstancestate);
setcontentview (R. layout. main);
bt = (button) This. findviewbyid (R. id. button1);
BT. setonclicklistener (New onclicklistener () {

@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Intent = new intent ();
Intent. setclass (activityintentactivity. This, secondactivity. Class );
Activityintentactivity. This. startactivity (intent );
Activityintentactivity. This. Finish ();
}

});
}
}

Secondactivity. Java

 

Package gogler. myandroid;

Import Android. App. activity;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;

Public class secondactivity extends activity {
/** Called when the activity is first created .*/
Button Bt;
Intent intent;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. main2 );
Bt = (button) This. findviewbyid (R. Id. button2 );
Bt. setonclicklistener (New onclicklistener (){

@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Intent = new intent ();
Intent. setclass (secondactivity. This, activityintentactivity. Class );
Secondactivity. This. startactivity (intent );
Secondactivity. This. Finish ();
}

});
}
}

Demo:

 

Code Package

Http://download.csdn.net/download/gogler/3723721

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.