<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rainsong.intentdemo" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" /> <application android:label="@string/app_name" android:icon="@drawable/ic_launcher"> <activity android:name="MainActivity" 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="OtherActivity" android:label="OtherActivity"> </activity> </application> </manifest>布局文件:main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="跳转到另一个Activity" /> </LinearLayout>布局文件:other.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="OtherActivity" /> </LinearLayout>Java源代码文件:MainActivity.java
package com.rainsong.intentdemo; 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 MainActivity extends Activity { OnClickListener listener1 = null; Button button1; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listener1 = new OnClickListener() { public void onClick(View v) { Intent intent1= new Intent(MainActivity.this, OtherActivity.class); startActivity(intent1); } }; button1 = (Button)findViewById(R.id.button1); button1.setOnClickListener(listener1); } }
Java源代码文件:OtherActivity.java
package com.rainsong.intentdemo; import android.app.Activity; import android.os.Bundle; public class OtherActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.other); } }
原文地址:http://blog.csdn.net/hantangsongming/article/details/41073849