We once described in detail about Android Activity in an article. Here, we will further analyze this operation in detail. It is mainly for the implementation of Android Activity jump. Next let's take a look at the specific operation methods.
Android provides a kind called Intent to jump between screens. The following is a simple example:
Add an Activity in the application named. ForwardTarget). You need to modify the AndroidManifest. xml file, as shown below:
Android Activity jump code example:
- < ?xml version="1.0" encoding="utf-8"?>
- < manifest xmlns:android="< A href="http://schemas.android.com/
apk/res/android">http://schemas.android.com/apk/res/android< /A>"
- package="com.ray.forward"
- android:versionCode="1"
- android:versionName="1.0">
- < application android:icon="@drawable/icon"
android:label="@string/app_name">
- < activity android:name=".androidForward"
- 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=".ForwardTarget">
- < /activity>
- < /application>
- < uses-sdk android:minSdkVersion="3" />
- < /manifest>
- < ?xml version="1.0" encoding="utf-8"?>
- < manifest xmlns:android=
"http://schemas.android.com/apk/res/android"
- package="com.ray.forward"
- android:versionCode="1"
- android:versionName="1.0">
- < application android:icon="@drawable/icon"
android:label="@string/app_name">
- < activity android:name=".androidForward"
- 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=".ForwardTarget">
- < /activity>
- < /application>
- < uses-sdk android:minSdkVersion="3" />
- < /manifest>
Then add a button with the id of leah1 to main in layout, and create any layout to jump to layout.) I will name it leah1.
The following two classes are available: AndroidForward and ForwardTarget. The Android Activity jump implementation code is as follows:
- AndroidForw:
- Package com. ray. forward;
- Import android. app. Activity;
- Import android. content. Intent;
- Import android. OS. Bundle;
- Import android. view. View;
- Import android. widget. Button;
- Public class androidForward extends Activity {
- /** Called when the activity is first created .*/
- @ Override
- Public void onCreate (Bundle savedInstanceState ){
- Super. onCreate (savedInstanceState );
- SetContentView (R. layout. main );
- Button btn1 = (Button) findViewById (R. id. leah1 );
- Btn1.setOnClickListener (new View. OnClickListener (){
- @ Override
- Public void onClick (View v ){
- Intent intent = new Intent ();
- Intent. setClass (androidForward. this, ForwardTarget. class );
- StartActivity (intent );
- Finish ();
// Stop the current Activity. If the current Activity is not written, press the return key to jump back to the original Activity.
- }
- });
- }
- }
- Package com. ray. forward;
- Import android. app. Activity;
- Import android. content. Intent;
- Import android. OS. Bundle;
- Import android. view. View;
- Import android. widget. Button;
- Public class androidForward extends Activity {
- /** Called when the activity is first created .*/
- @ Override
- Public void onCreate (Bundle savedInstanceState ){
- Super. onCreate (savedInstanceState );
- SetContentView (R. layout. main );
- Button btn1 = (Button) findViewById (R. id. leah1 );
- Btn1.setOnClickListener (new View. OnClickListener (){
- @ Override
- Public void onClick (View v ){
- Intent intent = new Intent ();
- Intent. setClass (androidForward. this, ForwardTarget. class );
- StartActivity (intent );
- Finish ();
// Stop the current Activity. If the current Activity is not written, press the return key to jump back to the original Activity.
- }
- });
- }
- }
- ForwardTarget:
- Package com. ray. forward;
- Import android. app. Activity;
- Import android. OS. Bundle;
- Public class ForwardTarget extends Activity {
- @ Override
- Protected void onCreate (Bundle savedInstanceState ){
- // TODO Auto-generated method stub
- Super. onCreate (savedInstanceState );
- SetContentView (R. layout. leah1 );
- }
- }
The implementation of Android Activity redirection is described here.