Android Activity jump related operation tips

Source: Internet
Author: User

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:

 
 
  1. < ?xml version="1.0" encoding="utf-8"?>   
  2. < manifest xmlns:android="< A href="http://schemas.android.com/
    apk/res/android">http://schemas.android.com/apk/res/android< /A>"   
  3. package="com.ray.forward"   
  4. android:versionCode="1"   
  5. android:versionName="1.0">   
  6. < application android:icon="@drawable/icon" 
    android:label="@string/app_name">   
  7. < activity android:name=".androidForward"   
  8. android:label="@string/app_name">   
  9. < intent-filter>   
  10. < action android:name="android.intent.action.MAIN" />   
  11. < category android:name="android.intent.category.LAUNCHER" />   
  12. < /intent-filter>   
  13. < /activity>   
  14. < activity android:name=".ForwardTarget">   
  15. < /activity>   
  16. < /application>   
  17. < uses-sdk android:minSdkVersion="3" />   
  18. < /manifest>   
  19. < ?xml version="1.0" encoding="utf-8"?> 
  20. < manifest xmlns:android=
    "http://schemas.android.com/apk/res/android" 
  21. package="com.ray.forward" 
  22. android:versionCode="1" 
  23. android:versionName="1.0"> 
  24. < application android:icon="@drawable/icon" 
    android:label="@string/app_name"> 
  25. < activity android:name=".androidForward" 
  26. android:label="@string/app_name"> 
  27. < intent-filter> 
  28. < action android:name="android.intent.action.MAIN" /> 
  29. < category android:name="android.intent.category.LAUNCHER" /> 
  30. < /intent-filter> 
  31. < /activity> 
  32. < activity android:name=".ForwardTarget"> 
  33. < /activity> 
  34. < /application> 
  35. < uses-sdk android:minSdkVersion="3" /> 
  36. < /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:

 
 
  1. AndroidForw:
  2. Package com. ray. forward;
  3. Import android. app. Activity;
  4. Import android. content. Intent;
  5. Import android. OS. Bundle;
  6. Import android. view. View;
  7. Import android. widget. Button;
  8. Public class androidForward extends Activity {
  9. /** Called when the activity is first created .*/
  10. @ Override
  11. Public void onCreate (Bundle savedInstanceState ){
  12. Super. onCreate (savedInstanceState );
  13. SetContentView (R. layout. main );
  14. Button btn1 = (Button) findViewById (R. id. leah1 );
  15. Btn1.setOnClickListener (new View. OnClickListener (){
  16. @ Override
  17. Public void onClick (View v ){
  18. Intent intent = new Intent ();
  19. Intent. setClass (androidForward. this, ForwardTarget. class );
  20. StartActivity (intent );
  21. Finish ();
    // Stop the current Activity. If the current Activity is not written, press the return key to jump back to the original Activity.
  22. }
  23. });
  24. }
  25. }
  26. Package com. ray. forward;
  27. Import android. app. Activity;
  28. Import android. content. Intent;
  29. Import android. OS. Bundle;
  30. Import android. view. View;
  31. Import android. widget. Button;
  32. Public class androidForward extends Activity {
  33. /** Called when the activity is first created .*/
  34. @ Override
  35. Public void onCreate (Bundle savedInstanceState ){
  36. Super. onCreate (savedInstanceState );
  37. SetContentView (R. layout. main );
  38. Button btn1 = (Button) findViewById (R. id. leah1 );
  39. Btn1.setOnClickListener (new View. OnClickListener (){
  40. @ Override
  41. Public void onClick (View v ){
  42. Intent intent = new Intent ();
  43. Intent. setClass (androidForward. this, ForwardTarget. class );
  44. StartActivity (intent );
  45. Finish ();
    // Stop the current Activity. If the current Activity is not written, press the return key to jump back to the original Activity.
  46. }
  47. });
  48. }
  49. }
  50. ForwardTarget:
  51. Package com. ray. forward;
  52. Import android. app. Activity;
  53. Import android. OS. Bundle;
  54. Public class ForwardTarget extends Activity {
  55. @ Override
  56. Protected void onCreate (Bundle savedInstanceState ){
  57. // TODO Auto-generated method stub
  58. Super. onCreate (savedInstanceState );
  59. SetContentView (R. layout. leah1 );
  60. }
  61. }

The implementation of Android Activity redirection is described here.

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.