从零开始学android<Intent初步.四十.>

Intent意图是android中非常重要的部分,他在Activity,service中有较为广泛的应用。


1

public void startActivity(Intent intent)

普通

启动一个Activity,并通过Intent传送数据

2

public void startActivityForResult(Intent intent, int requestCode)

普通

启动并接收另一个Activity程序回传数据,当requestCode大于0才可以触发onActivityResult()

3

public Intent getIntent()

普通

返回启动当前Activity程序的Intent

4

protected void onActivityResult(int requestCode, int resultCode, Intent data)

普通

当需要接收Intent回传数据的时候覆写此方法对回传操作进行处理

5

public void finish()

普通

调用此方法会返回之前的Activity程序,并自动调用onActivityResult()方法

6

public final Cursor managedQuery (Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

普通

处理返回的Cursor结果集

接下里用例子逐步讲解

最简单的Intent

主界面xml

[html] view plaincopyprint?

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingBottom="@dimen/activity_vertical_margin"
  6. android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. tools:context=".MainActivity" >
  10. <TextView
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:text="@string/hello_world" />
  14. <Button
  15. android:id="@+id/button1"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:layout_alignParentBottom="true"
  19. android:layout_centerHorizontal="true"
  20. android:layout_marginBottom="141dp"
  21. android:text="转跳" />
  22. </RelativeLayout>

转跳界面Xml

[html] view plaincopyprint?

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingBottom="@dimen/activity_vertical_margin"
  6. android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. tools:context=".MainActivity" >
  10. <TextView
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:text="我是第二屏界面" />
  14. </RelativeLayout>

[java] view plaincopyprint?

  1. package com.example.intent1;
  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.view.Menu;
  6. import android.view.View;
  7. import android.widget.Button;
  8. public class MainActivity extends Activity {
  9. private Button button;
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14. button = (Button) this.findViewById(R.id.button1);
  15. button.setOnClickListener(new View.OnClickListener() {
  16. @Override
  17. public void onClick(View v) {
  18. // TODO Auto-generated method stub
  19. Intent intent = new Intent(MainActivity.this, Other.class);//创建Intent 对象
  20. startActivity(intent);//开启intent
  21. MainActivity.this.finish();//使当前Activity结束
  22. }
  23. });
  24. }
  25. }

Otner.java

[java] view plaincopyprint?

  1. package com.example.intent1;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.text.style.SuperscriptSpan;
  5. public class Other extends Activity {
  6. @Override
  7. protected void onCreate(Bundle savedInstanceState) {
  8. // TODO Auto-generated method stub
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.other);
  11. }
  12. }

接下来看一看可以传递数据的Intent

[html] view plaincopyprint?

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:paddingBottom="@dimen/activity_vertical_margin"
  6. android:paddingLeft="@dimen/activity_horizontal_margin"
  7. android:paddingRight="@dimen/activity_horizontal_margin"
  8. android:paddingTop="@dimen/activity_vertical_margin"
  9. tools:context=".MainActivity" >
  10. <Button
  11. android:id="@+id/button1"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:layout_alignParentBottom="true"
  15. android:layout_centerHorizontal="true"
  16. android:text="传递" />
  17. <EditText
  18. android:id="@+id/edit"
  19. android:layout_width="wrap_content"
  20. android:layout_height="wrap_content"
  21. android:layout_alignParentTop="true"
  22. android:layout_centerHorizontal="true"
  23. android:ems="10"
  24. android:text=" />
  25. </RelativeLayout>
  26. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  27. xmlns:tools="http://schemas.android.com/tools"
  28. android:layout_width="match_parent"
  29. android:layout_height="match_parent"
  30. android:paddingBottom="@dimen/activity_vertical_margin"
  31. android:paddingLeft="@dimen/activity_horizontal_margin"
  32. android:paddingRight="@dimen/activity_horizontal_margin"
  33. android:paddingTop="@dimen/activity_vertical_margin"
  34. tools:context=".MainActivity" >
  35. <Button
  36. android:id="@+id/button1"
  37. android:layout_width="wrap_content"
  38. android:layout_height="wrap_content"
  39. android:layout_alignParentBottom="true"
  40. android:layout_centerHorizontal="true"
  41. android:text="传递" />
  42. <EditText
  43. android:id="@+id/edit"
  44. android:layout_width="wrap_content"
  45. android:layout_height="wrap_content"
  46. android:layout_alignParentTop="true"
  47. android:layout_centerHorizontal="true"
  48. android:ems="10"
  49. android:text="" />
  50. </RelativeLayout>

Other.xml

[html] view plaincopyprint?

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <TextView
  7. android:id="@+id/textView1"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:text="TextView" />
  11. <Button
  12. android:id="@+id/button2"
  13. android:gravity="center_horizontal"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:text="获取数据" />
  17. </LinearLayout>

java文件

[java] view plaincopyprint?

  1. package com.example.intent2;
  2. import android.os.Bundle;
  3. import android.R.integer;
  4. import android.app.Activity;
  5. import android.content.Intent;
  6. import android.view.Menu;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. public class MainActivity extends Activity {
  11. private Button button;
  12. private EditText info;
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.activity_main);
  17. button=(Button)this.findViewById(R.id.button1);
  18. info=(EditText)this.findViewById(R.id.edit);
  19. button.setOnClickListener(new View.OnClickListener() {
  20. @Override
  21. public void onClick(View v) {
  22. // TODO Auto-generated method stub
  23. Intent intent=new Intent(MainActivity.this,Other.class);//设置意图
  24. intent.putExtra("info", info.getText().toString());//为意图增加附加信息
  25. startActivity(intent);//开始意图
  26. MainActivity.this.finish();//终止当前Ativity
  27. }
  28. });
  29. }
  30. }

Other.java

[java] view plaincopyprint?

  1. package com.example.intent2;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.TextView;
  8. public class Other extends Activity {
  9. Intent intent;
  10. private Button button;
  11. private TextView text;
  12. @Override
  13. protected void onCreate(Bundle savedInstanceState) {
  14. // TODO Auto-generated method stub
  15. super.onCreate(savedInstanceState);
  16. super.setContentView(R.layout.other);
  17. button=(Button)this.findViewById(R.id.button2);
  18. text=(TextView)this.findViewById(R.id.textView1);
  19. intent=super.getIntent();//获取意图对象
  20. button.setOnClickListener(new View.OnClickListener() {
  21. @Override
  22. public void onClick(View v) {
  23. // TODO Auto-generated method stub
  24. String info=intent.getStringExtra("info");//获取传递的数据
  25. text.setText(info);//显示数据
  26. }
  27. });
  28. }
  29. }

使用Intent传递并返回数据

借助Intent实现成人身高体重测试程序

采用BMI 法 

体重指数 =  体重(公斤) 除 身高(米)的平方    kg/m2
正常体重 : 体重指数 = 18 - 25
超重           : 体重指数 = 25 - 30
轻度肥胖 : 体重指数 > 30
中度肥胖 : 体重指数 > 35
重度肥胖 :  体重指数 > 40 

xml

[java] view plaincopyprint?

  1. package com.example.inten3;
  2. import android.os.Bundle;
  3. import android.app.Activity;
  4. import android.content.Intent;
  5. import android.view.Menu;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10. public class MainActivity extends Activity {
  11. private Button resetInfo,getInfo;
  12. private EditText height,weight;
  13. private TextView detail;
  14. @Override
  15. protected void onCreate(Bundle savedInstanceState) {
  16. super.onCreate(savedInstanceState);
  17. super.setContentView(R.layout.activity_main);
  18. resetInfo=(Button)this.findViewById(R.id.button1);//重置信息按钮
  19. getInfo=(Button)this.findViewById(R.id.button2);//获取信息按钮
  20. height=(EditText)this.findViewById(R.id.editText1);//身高输入框
  21. weight=(EditText)this.findViewById(R.id.editText2);//体重输入框
  22. detail=(TextView)this.findViewById(R.id.textView3);//信息显示
  23. //   重置按钮的监听
  24. resetInfo.setOnClickListener(new View.OnClickListener() {
  25. @Override
  26. public void onClick(View v) {
  27. // TODO Auto-generated method stub
  28. //将他们都设置为空
  29. weight.setText("");
  30. height.setText("");
  31. detail.setText("");
  32. }
  33. });
  34. //  获取信息按钮的监听
  35. getInfo.setOnClickListener(new View.OnClickListener() {
  36. @Override
  37. public void onClick(View v) {
  38. // TODO Auto-generated method stub
  39. Intent intent =new  Intent(MainActivity.this, Other.class);//创建意图对象
  40. //  增加附加信息
  41. intent.putExtra("weight", Double.valueOf(weight.getText().toString()));
  42. intent.putExtra("height", Double.valueOf(height.getText().toString()));
  43. //设置启动并传递请求码
  44. startActivityForResult(intent, 1);
  45. }
  46. });
  47. }
  48. //    处理返回的信息
  49. @Override
  50. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  51. // TODO Auto-generated method stub
  52. switch (resultCode) {
  53. case RESULT_OK:
  54. //设置信息
  55. MainActivity.this.detail.setText(data.getStringExtra("endMsg"));
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. }
  62. http://blog.renren.com/blog/573785236/934703413
    http://guangzhou.baixing.com/qitafuwu/a417877410.html
    http://club.jd.com/CommunityGroupDetail/13057867_1.html
    http://club.jd.com/CommunityGroupDetail/13057868_1.html
    http://club.jd.com/CommunityGroupDetail/13057869_1.html
    http://club.jd.com/CommunityGroupDetail/13057960_1.html
    http://club.jd.com/CommunityGroupDetail/13057986_1.html
    http://club.jd.com/CommunityGroupDetail/13057988_1.html
    http://club.jd.com/CommunityGroupDetail/13058011_1.html
    http://club.jd.com/CommunityGroupDetail/13058019_1.html
    http://club.jd.com/CommunityGroupDetail/13058020_1.html
    http://club.jd.com/CommunityGroupDetail/13058038_1.html
    http://club.jd.com/CommunityGroupDetail/13058040_1.html
    http://club.jd.com/CommunityGroupDetail/13058045_1.html
    http://club.jd.com/CommunityGroupDetail/13058068_1.html
    http://club.jd.com/CommunityGroupDetail/13058074_1.html
    http://club.jd.com/CommunityGroupDetail/13058079_1.html
    http://club.jd.com/CommunityGroupDetail/13058092_1.html
    http://club.jd.com/CommunityGroupDetail/13058093_1.html
    http://club.jd.com/CommunityGroupDetail/13058096_1.html
    http://club.jd.com/CommunityGroupDetail/13058102_1.html
    http://club.jd.com/CommunityGroupDetail/13058104_1.html
    http://club.jd.com/CommunityGroupDetail/13058105_1.html
    http://club.jd.com/CommunityGroupDetail/13058130_1.html
    http://club.jd.com/CommunityGroupDetail/13058132_1.html
    http://club.jd.com/CommunityGroupDetail/13058133_1.html
    http://club.jd.com/CommunityGroupDetail/13058138_1.html
    http://club.jd.com/CommunityGroupDetail/13058139_1.html
    http://club.jd.com/CommunityGroupDetail/13058140_1.html
    http://club.jd.com/CommunityGroupDetail/13058163_1.html
    http://club.jd.com/CommunityGroupDetail/13058165_1.html
    http://club.jd.com/CommunityGroupDetail/13058170_1.html
    http://club.jd.com/CommunityGroupDetail/13058188_1.html
    http://club.jd.com/CommunityGroupDetail/13058210_1.html
    http://club.jd.com/CommunityGroupDetail/13058220_1.html
    http://club.jd.com/CommunityGroupDetail/13058229_1.html
    http://club.jd.com/CommunityGroupDetail/13058230_1.html
    http://club.jd.com/CommunityGroupDetail/13058241_1.html
    http://club.jd.com/CommunityGroupDetail/13058243_1.html
    http://club.jd.com/CommunityGroupDetail/13058244_1.html
    http://club.jd.com/CommunityGroupDetail/13058249_1.html
    http://club.jd.com/CommunityGroupDetail/13058260_1.html
    http://club.jd.com/CommunityGroupDetail/13058266_1.html
    http://club.jd.com/CommunityGroupDetail/13058274_1.html
    http://club.jd.com/CommunityGroupDetail/13058276_1.html
    http://club.jd.com/CommunityGroupDetail/13058278_1.html
    http://club.jd.com/CommunityGroupDetail/13058280_1.html
    http://club.jd.com/CommunityGroupDetail/13058288_1.html
    http://club.jd.com/CommunityGroupDetail/13058295_1.html
    http://club.jd.com/CommunityGroupDetail/13058299_1.html
    http://club.jd.com/CommunityGroupDetail/13058300_1.html
    http://club.jd.com/CommunityGroupDetail/13058301_1.html
    http://club.jd.com/CommunityGroupDetail/13058305_1.html
    http://club.jd.com/CommunityGroupDetail/13058316_1.html
    http://club.jd.com/CommunityGroupDetail/13058320_1.html
    http://club.jd.com/CommunityGroupDetail/13058322_1.html
    http://club.jd.com/CommunityGroupDetail/13058323_1.html
    http://club.jd.com/CommunityGroupDetail/13058330_1.html
    http://club.jd.com/CommunityGroupDetail/13058338_1.html
    http://club.jd.com/CommunityGroupDetail/13058339_1.html
    http://club.jd.com/CommunityGroupDetail/13058344_1.html
    http://club.jd.com/CommunityGroupDetail/13058351_1.html
    http://club.jd.com/CommunityGroupDetail/13058361_1.html
    http://club.jd.com/CommunityGroupDetail/13058363_1.html
    http://club.jd.com/CommunityGroupDetail/13058365_1.html
    http://club.jd.com/CommunityGroupDetail/13058368_1.html
    http://club.jd.com/CommunityGroupDetail/13058376_1.html
    http://club.jd.com/CommunityGroupDetail/13058378_1.html
    http://club.jd.com/CommunityGroupDetail/13058379_1.html
    http://club.jd.com/CommunityGroupDetail/13058381_1.html
    http://club.jd.com/CommunityGroupDetail/13058392_1.html
    http://club.jd.com/CommunityGroupDetail/13058393_1.html
    http://club.jd.com/CommunityGroupDetail/13058395_1.html
    http://club.jd.com/CommunityGroupDetail/13058400_1.html
    http://club.jd.com/CommunityGroupDetail/13058402_1.html
    http://club.jd.com/CommunityGroupDetail/13058408_1.html
    http://club.jd.com/CommunityGroupDetail/13058416_1.html
    http://club.jd.com/CommunityGroupDetail/13058417_1.html
    http://club.jd.com/CommunityGroupDetail/13058429_1.html
    http://club.jd.com/CommunityGroupDetail/13058435_1.html
    http://club.jd.com/CommunityGroupDetail/13058436_1.html
    http://club.jd.com/CommunityGroupDetail/13058441_1.html
    http://club.jd.com/CommunityGroupDetail/13058442_1.html
    http://club.jd.com/CommunityGroupDetail/13058443_1.html
    http://club.jd.com/CommunityGroupDetail/13058450_1.html
    http://club.jd.com/CommunityGroupDetail/13058460_1.html
    http://club.jd.com/CommunityGroupDetail/13058465_1.html
    http://club.jd.com/CommunityGroupDetail/13058466_1.html
    http://club.jd.com/CommunityGroupDetail/13058469_1.html
    http://club.jd.com/CommunityGroupDetail/13058474_1.html
    http://club.jd.com/CommunityGroupDetail/13058475_1.html
    http://club.jd.com/CommunityGroupDetail/13058481_1.html
    http://club.jd.com/CommunityGroupDetail/13058487_1.html
    http://club.jd.com/CommunityGroupDetail/13058491_1.html
    http://club.jd.com/CommunityGroupDetail/13058493_1.html
    http://club.jd.com/CommunityGroupDetail/13058499_1.html
    http://club.jd.com/CommunityGroupDetail/13058500_1.html
    http://club.jd.com/CommunityGroupDetail/13058502_1.html
    http://club.jd.com/CommunityGroupDetail/13058504_1.html
    http://club.jd.com/CommunityGroupDetail/13058506_1.html
    http://club.jd.com/CommunityGroupDetail/13058508_1.html
    http://club.jd.com/CommunityGroupDetail/13058513_1.html
    http://club.jd.com/CommunityGroupDetail/13058524_1.html
    http://club.jd.com/CommunityGroupDetail/13058526_1.html
    http://club.jd.com/CommunityGroupDetail/13058529_1.html
    http://club.jd.com/CommunityGroupDetail/13058536_1.html
    http://club.jd.com/CommunityGroupDetail/13058537_1.html
    http://club.jd.com/CommunityGroupDetail/13058538_1.html
    http://club.jd.com/CommunityGroupDetail/13058539_1.html
    http://club.jd.com/CommunityGroupDetail/13058542_1.html
    http://club.jd.com/CommunityGroupDetail/13058543_1.html
    http://club.jd.com/CommunityGroupDetail/13058544_1.html
    http://club.jd.com/CommunityGroupDetail/13058549_1.html
    http://club.jd.com/CommunityGroupDetail/13058550_1.html
    http://club.jd.com/CommunityGroupDetail/13058555_1.html
    http://club.jd.com/CommunityGroupDetail/13058559_1.html
    http://club.jd.com/CommunityGroupDetail/13058562_1.html
    http://club.jd.com/CommunityGroupDetail/13058565_1.html
    http://club.jd.com/CommunityGroupDetail/13058567_1.html
    http://club.jd.com/CommunityGroupDetail/13058572_1.html
    http://club.jd.com/CommunityGroupDetail/13058573_1.html
    http://club.jd.com/CommunityGroupDetail/13058576_1.html
    http://club.jd.com/CommunityGroupDetail/13058579_1.html
    http://club.jd.com/CommunityGroupDetail/13058580_1.html
    http://club.jd.com/CommunityGroupDetail/13058595_1.html
    http://club.jd.com/CommunityGroupDetail/13058600_1.html
    http://club.jd.com/CommunityGroupDetail/13058601_1.html
    http://club.jd.com/CommunityGroupDetail/13058602_1.html
    http://club.jd.com/CommunityGroupDetail/13058603_1.html
    http://club.jd.com/CommunityGroupDetail/13058609_1.html
    http://club.jd.com/CommunityGroupDetail/13058613_1.html
    http://club.jd.com/CommunityGroupDetail/13058615_1.html
    http://club.jd.com/CommunityGroupDetail/13058618_1.html
    http://club.jd.com/CommunityGroupDetail/13058621_1.html
    http://club.jd.com/CommunityGroupDetail/13058622_1.html
    http://club.jd.com/CommunityGroupDetail/13058631_1.html
    http://club.jd.com/CommunityGroupDetail/13058636_1.html
    http://club.jd.com/CommunityGroupDetail/13058645_1.html
    http://club.jd.com/CommunityGroupDetail/13058651_1.html
    http://club.jd.com/CommunityGroupDetail/13058658_1.html
    http://club.jd.com/CommunityGroupDetail/13058662_1.html
    http://club.jd.com/CommunityGroupDetail/13058670_1.html
    http://club.jd.com/CommunityGroupDetail/13058671_1.html
    http://club.jd.com/CommunityGroupDetail/13058672_1.html
    http://club.jd.com/CommunityGroupDetail/13058691_1.html
    http://club.jd.com/CommunityGroupDetail/13058692_1.html
    http://club.jd.com/CommunityGroupDetail/13058693_1.html
    http://club.jd.com/CommunityGroupDetail/13058694_1.html
    http://club.jd.com/CommunityGroupDetail/13058695_1.html
    http://club.jd.com/CommunityGroupDetail/13058696_1.html
    http://club.jd.com/CommunityGroupDetail/13058708_1.html
    http://club.jd.com/CommunityGroupDetail/13058719_1.html
    http://club.jd.com/CommunityGroupDetail/13058727_1.html
    http://club.jd.com/CommunityGroupDetail/13058728_1.html
    http://club.jd.com/CommunityGroupDetail/13058732_1.html
    http://club.jd.com/CommunityGroupDetail/13058733_1.html
    http://club.jd.com/CommunityGroupDetail/13058734_1.html
    http://club.jd.com/CommunityGroupDetail/13058736_1.html
    http://club.jd.com/CommunityGroupDetail/13058738_1.html
    http://club.jd.com/CommunityGroupDetail/13058740_1.html
    http://club.jd.com/CommunityGroupDetail/13058743_1.html
    http://club.jd.com/CommunityGroupDetail/13058746_1.html
    http://club.jd.com/CommunityGroupDetail/13058748_1.html
    http://club.jd.com/CommunityGroupDetail/13058751_1.html
    http://club.jd.com/CommunityGroupDetail/13058755_1.html
    http://club.jd.com/CommunityGroupDetail/13058757_1.html
    http://club.jd.com/CommunityGroupDetail/13058760_1.html
    http://club.jd.com/CommunityGroupDetail/13058763_1.html
    http://club.jd.com/CommunityGroupDetail/13058767_1.html
    http://club.jd.com/CommunityGroupDetail/13058770_1.html
    http://club.jd.com/CommunityGroupDetail/13058771_1.html
    http://club.jd.com/CommunityGroupDetail/13058776_1.html
    http://club.jd.com/CommunityGroupDetail/13058784_1.html
    http://club.jd.com/CommunityGroupDetail/13058786_1.html
    http://club.jd.com/CommunityGroupDetail/13058787_1.html
    http://club.jd.com/CommunityGroupDetail/13058792_1.html
    http://club.jd.com/CommunityGroupDetail/13058793_1.html
    http://club.jd.com/CommunityGroupDetail/13058795_1.html
    http://club.jd.com/CommunityGroupDetail/13058797_1.html
    http://club.jd.com/CommunityGroupDetail/13058802_1.html
    http://club.jd.com/CommunityGroupDetail/13058810_1.html
    http://club.jd.com/CommunityGroupDetail/13058813_1.html
    http://club.jd.com/CommunityGroupDetail/13058815_1.html
    http://club.jd.com/CommunityGroupDetail/13058818_1.html
    http://club.jd.com/CommunityGroupDetail/13058823_1.html
    http://club.jd.com/CommunityGroupDetail/13058824_1.html
    http://club.jd.com/CommunityGroupDetail/13058825_1.html
    http://club.jd.com/CommunityGroupDetail/13058828_1.html
    http://club.jd.com/CommunityGroupDetail/13058831_1.html
    http://club.jd.com/CommunityGroupDetail/13058833_1.html
    http://club.jd.com/CommunityGroupDetail/13058835_1.html
    http://club.jd.com/CommunityGroupDetail/13058839_1.html
    http://club.jd.com/CommunityGroupDetail/13058844_1.html
    http://club.jd.com/CommunityGroupDetail/13058848_1.html
    http://club.jd.com/CommunityGroupDetail/13058851_1.html
    http://club.jd.com/CommunityGroupDetail/13058857_1.html
    http://club.jd.com/CommunityGroupDetail/13058858_1.html
    http://club.jd.com/CommunityGroupDetail/13058861_1.html
    http://club.jd.com/CommunityGroupDetail/13058864_1.html
    http://club.jd.com/CommunityGroupDetail/13058869_1.html
    http://club.jd.com/CommunityGroupDetail/13058872_1.html
    http://club.jd.com/CommunityGroupDetail/13058878_1.html
    http://club.jd.com/CommunityGroupDetail/13058879_1.html
    http://club.jd.com/CommunityGroupDetail/13058880_1.html
    http://club.jd.com/CommunityGroupDetail/13058888_1.html
    http://club.jd.com/CommunityGroupDetail/13058890_1.html
    http://club.jd.com/CommunityGroupDetail/13058897_1.html
    http://club.jd.com/CommunityGroupDetail/13058898_1.html
    http://club.jd.com/CommunityGroupDetail/13058900_1.html
    http://club.jd.com/CommunityGroupDetail/13058903_1.html
    http://club.jd.com/CommunityGroupDetail/13058919_1.html
    http://club.jd.com/CommunityGroupDetail/13058923_1.html
    http://club.jd.com/CommunityGroupDetail/13058931_1.html
    http://club.jd.com/CommunityGroupDetail/13058942_1.html
    http://club.jd.com/CommunityGroupDetail/13058945_1.html
    http://club.jd.com/CommunityGroupDetail/13058953_1.html
    http://club.jd.com/CommunityGroupDetail/13058954_1.html
    http://club.jd.com/CommunityGroupDetail/13058958_1.html
    http://club.jd.com/CommunityGroupDetail/13058960_1.html
    http://club.jd.com/CommunityGroupDetail/13058963_1.html
    http://club.jd.com/CommunityGroupDetail/13058979_1.html
    http://club.jd.com/CommunityGroupDetail/13058983_1.html
    http://club.jd.com/CommunityGroupDetail/13058985_1.html
    http://club.jd.com/CommunityGroupDetail/13058986_1.html
    http://club.jd.com/CommunityGroupDetail/13058991_1.html
    http://club.jd.com/CommunityGroupDetail/13058995_1.html
    http://club.jd.com/CommunityGroupDetail/13058997_1.html
    http://club.jd.com/CommunityGroupDetail/13058999_1.html
    http://club.jd.com/CommunityGroupDetail/13059000_1.html
    http://club.jd.com/CommunityGroupDetail/13059004_1.html
    http://club.jd.com/CommunityGroupDetail/13059022_1.html
    http://club.jd.com/CommunityGroupDetail/13059023_1.html
    http://club.jd.com/CommunityGroupDetail/13059032_1.html
    http://club.jd.com/CommunityGroupDetail/13059062_1.html
    http://club.jd.com/CommunityGroupDetail/13059063_1.html
    http://club.jd.com/CommunityGroupDetail/13059064_1.html
    http://club.jd.com/CommunityGroupDetail/13059069_1.html
    http://club.jd.com/CommunityGroupDetail/13059078_1.html
    http://club.jd.com/CommunityGroupDetail/13059080_1.html
    http://club.jd.com/CommunityGroupDetail/13059092_1.html
    http://club.jd.com/CommunityGroupDetail/13059094_1.html
    http://club.jd.com/CommunityGroupDetail/13059095_1.html
    http://club.jd.com/CommunityGroupDetail/13059100_1.html
    http://club.jd.com/CommunityGroupDetail/13059101_1.html
    http://club.jd.com/CommunityGroupDetail/13059108_1.html
    http://club.jd.com/CommunityGroupDetail/13059112_1.html
    http://club.jd.com/CommunityGroupDetail/13059118_1.html
    http://club.jd.com/CommunityGroupDetail/13059119_1.html
    http://club.jd.com/CommunityGroupDetail/13059124_1.html
    http://club.jd.com/CommunityGroupDetail/13059131_1.html
    http://club.jd.com/CommunityGroupDetail/13059141_1.html
    http://club.jd.com/CommunityGroupDetail/13059143_1.html
    http://club.jd.com/CommunityGroupDetail/13059151_1.html
    http://club.jd.com/CommunityGroupDetail/13059158_1.html
    http://club.jd.com/CommunityGroupDetail/13059186_1.html
    http://club.jd.com/CommunityGroupDetail/13059189_1.html
    http://club.jd.com/CommunityGroupDetail/13059195_1.html
    http://club.jd.com/CommunityGroupDetail/13059205_1.html
    http://club.jd.com/CommunityGroupDetail/13059209_1.html
    http://club.jd.com/CommunityGroupDetail/13059210_1.html
    http://club.jd.com/CommunityGroupDetail/13059211_1.html
    http://club.jd.com/CommunityGroupDetail/13059222_1.html
    http://club.jd.com/CommunityGroupDetail/13059230_1.html
    http://club.jd.com/CommunityGroupDetail/13059232_1.html
    http://club.jd.com/CommunityGroupDetail/13059233_1.html
    http://club.jd.com/CommunityGroupDetail/13059240_1.html
    http://club.jd.com/CommunityGroupDetail/13059242_1.html
    http://club.jd.com/CommunityGroupDetail/13059252_1.html
    http://club.jd.com/CommunityGroupDetail/13059267_1.html
    http://club.jd.com/CommunityGroupDetail/13059311_1.html
    http://club.jd.com/CommunityGroupDetail/13059319_1.html
    http://club.jd.com/CommunityGroupDetail/13059320_1.html
    http://club.jd.com/CommunityGroupDetail/13059324_1.html
    http://club.jd.com/CommunityGroupDetail/13059329_1.html
    http://club.jd.com/CommunityGroupDetail/13059342_1.html
    http://club.jd.com/CommunityGroupDetail/13059343_1.html
    http://club.jd.com/CommunityGroupDetail/13059349_1.html
    http://club.jd.com/CommunityGroupDetail/13059356_1.html
    http://club.jd.com/CommunityGroupDetail/13059374_1.html
    http://club.jd.com/CommunityGroupDetail/13059377_1.html
    http://club.jd.com/CommunityGroupDetail/13059381_1.html
    http://club.jd.com/CommunityGroupDetail/13059382_1.html
    http://club.jd.com/CommunityGroupDetail/13059383_1.html
    http://club.jd.com/CommunityGroupDetail/13059408_1.html
    http://club.jd.com/CommunityGroupDetail/13059431_1.html
    http://club.jd.com/CommunityGroupDetail/13059440_1.html
    http://club.jd.com/CommunityGroupDetail/13059496_1.html
    http://club.jd.com/CommunityGroupDetail/13059497_1.html
    http://club.jd.com/CommunityGroupDetail/13059498_1.html
    http://club.jd.com/CommunityGroupDetail/13059522_1.html
    http://club.jd.com/CommunityGroupDetail/13059525_1.html
    http://club.jd.com/CommunityGroupDetail/13059552_1.html
    http://club.jd.com/CommunityGroupDetail/13059611_1.html

Other.java

[java] view plaincopyprint?

  1. package com.example.inten3;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.Button;
  7. import android.widget.TextView;
  8. public class Other extends Activity {
  9. private Button returnMsg, resetbut;
  10. private TextView weightMsg, heightMsg;
  11. private Double weight, height;
  12. private String endMsg;
  13. @Override
  14. protected void onCreate(Bundle savedInstanceState) {
  15. // TODO Auto-generated method stub
  16. super.onCreate(savedInstanceState);
  17. super.setContentView(R.layout.other);
  18. returnMsg = (Button) this.findViewById(R.id.Otherbutton1);
  19. resetbut = (Button) this.findViewById(R.id.Otherbutton2);
  20. weightMsg = (TextView) this.findViewById(R.id.OthertextView1);
  21. heightMsg = (TextView) this.findViewById(R.id.OthertextView2);
  22. // 获取意图对象
  23. Intent intent = super.getIntent();
  24. // 获得参数
  25. weight = intent.getDoubleExtra("weight", 0);
  26. height = intent.getDoubleExtra("height", 0);
  27. weightMsg.setText("您的体重:" + weight + "KG");
  28. heightMsg.setText("您的身高:" + height + "CM");
  29. returnMsg.setOnClickListener(new View.OnClickListener() {
  30. // 对传入的数据进项判断和处理
  31. @Override
  32. public void onClick(View v) {
  33. // TODO Auto-generated method stub
  34. Double heightNum = height / 100;
  35. double endNum = weight / (heightNum * heightNum);
  36. if (endNum >= 18 && endNum <= 25) {
  37. endMsg = "您的身体很正常哦,继续保持亲。";
  38. } else if (endNum < 18) {
  39. endMsg = "亲啊,不能总是减肥啊,您现在可是偏瘦哦,当心身体";
  40. } else if (endNum > 25 && endNum <= 30) {
  41. endMsg = "您现在有一点胖哦,不过不要紧,要注意饮食哦";
  42. } else if (endNum > 30 && endNum <= 35) {
  43. endMsg = "亲,您已经进入肥胖人群 了哦,注意锻炼哦";
  44. } else if (endNum > 35) {
  45. endMsg = "额,你,你。。你怎么可以这样,还不赶快减肥,当心找不到对象哦";
  46. }
  47. // 将参数设置到intnet上
  48. Other.this.getIntent().putExtra("endMsg", endMsg);
  49. // 设置返回集,并设置返回接受码
  50. Other.this.setResult(RESULT_OK, Other.this.getIntent());
  51. // 将dangqianActivity结束掉
  52. Other.this.finish();
  53. }
  54. });
  55. // 重新输入监听
  56. resetbut.setOnClickListener(new View.OnClickListener() {
  57. @Override
  58. public void onClick(View v) {
  59. // TODO Auto-generated method stub
  60. // 设置返回集合取消状态码
  61. Other.this.setResult(RESULT_CANCELED, Other.this.getIntent());
  62. // 结束当前Activity
  63. Other.this.finish();
  64. }
  65. });
  66. }
  67. }

学习了intent的基本用途,下节我们来学习Intent调用系统指令来完成一些其他操作

下节预报:Intent进阶

时间: 2024-11-06 04:31:59

从零开始学android<Intent初步.四十.>的相关文章

从零开始学android&lt;android事件的处理方式.二十四.&gt;

在android中一共有 多种事件,每种事件都有自己相对应的处理机制 如以下几种 1 单击事件 View.OnClickListener public abstract void onClick (View v) 单击组件时触发 2 单击事件 View.OnLongClickListener public abstract boolean onLongClick (View v) 长按组件时触发 3 键盘事件 View.OnKeyListener public abstract boolean

二十四、Android文件的读写

Android的文件读写与JavaSE的文件读写相同,都是使用IO流.而且Android使用的正是JavaSE的IO流,下面我们通过一个练习来学习Android的文件读写. 1.创建一个Android工程 [html] view plaincopy Project name:File BuildTarget:Android2.2 Application name:文件读写 Package name:test.file Create Activity:DateActivity Min SDK Ve

Android学习笔记二十四之ListView列表视图二

Android学习笔记二十四之ListView列表视图二 前面一篇我们介绍了常用的几种适配器的简单实现和ListView的简单使用,这一篇中,我们介绍一下ListView的优化和一些其它的问题. ListView优化方法一 在ListView中,我们最常用的就是自定义Adapter,在我们自定义Adapter中,需要实现两个比较重要的方法getCount()和getView(),前者是负责计算ListView的总Item数,后者是生成Item,有多少个Item就会调用getView()方法多少次

Android学习路线(二十四)ActionBar Fragment运用最佳实践

通过前面的几篇博客,大家看到了Google是如何解释action bar和fragment以及推荐的用法.俗话说没有demo的博客不是好博客,下面我会介绍一下action bar和fragment在实战中的应用,以及相关demo源码,希望和大家相互交流. 了解过fragment的同学们应该都知道,fragment是android 3.0版本才出现的的,因此如果要在支持android 3.0一下版本的工程中使用fragment的话是需要添加Support Library的.具体如何添加我就不再赘述

Android 沉浸式状态栏 实现方式二 ( 更简单 )

以前写过一个沉浸式状态栏 的实现方式 Android 沉浸式状态栏 实现方式一 现在有个更为简单的实现方式 . 相关链接 http://www.apkbus.com/forum.php?mod=viewthread&tid=255929&extra=page%3D3%26filter%3Dsortid%26orderby%3Ddateline%26sortid%3D12 1.效果图 demo 的 github 地址  https://github.com/zyj1609wz/Android

Android笔记二十四.Android基于回调的事件处理机制

如果说事件监听机制是一种委托式的事件处理,那么回调机制则与之相反,对于基于回调的事件处理模型来说,事件源和事件监听器是统一的,或者说事件监听器完全消失了,当用户在GUI控件上激发某个事件时,控件自己特定的方法将会负责处理该事件. 转载请表明出处:http://blog.csdn.net/u012637501(嵌入式_小J的天空) 一.View类的常见回调方法 为了使用回调机制来处理GUI控件上所发生的事件,需要为该组件提供对应的事件处理方法,而Java又是一种静态语言,我们无法为每个对象动态地添

Android开发系列(二十四):Notification的功能与用法

关于消息的提示有两种:一种是Toast,一种就是Notification.前者维持的时间比较短暂,后者维持的时间比较长. 而且我们平常手机的应用比如网易.贴吧等等都有很多的推送消息,就是用Notification实现的. Notification是显示在手机状态栏的通知-手机状态栏位于手机屏幕的上方.程序一般通过NotificationManager服务来发送Notification通知 Notification的一些方法,接下来我们都能够用到: setDefaults():设置通知LED等.音

Android学习笔记二十四.Service入门(二)绑定本地Service并与之通信

绑定本地Service并与之通信    通过上一篇博文的前3步,我们就算完成了一个Service及使用该Service的应用程序(Service为该应用程序的组成部分).但当程序通过startService()和stopService()启动.关闭Service时,Service与访问者之间基本上不存在太多的关联,因此Service和访问者之间也无法进行通信.数据交换.如果我们希望开发的Service能与访问者之间实现方法调用或数据交换,我们可以让访问者使用bindService()和unbin

Android开发系列(二十四):Notification的功能与使用方法

关于消息的提示有两种:一种是Toast,一种就是Notification.前者维持的时间比較短暂,后者维持的时间比較长. 并且我们寻常手机的应用比方网易.贴吧等等都有非常多的推送消息.就是用Notification实现的. Notification是显示在手机状态栏的通知-手机状态栏位于手机屏幕的上方.程序一般通过NotificationManager服务来发送Notification通知 Notification的一些方法.接下来我们都可以用到: setDefaults():设置通知LED等.

《Android源码设计模式解析与实战》读书笔记(二十四)

第二十四章.桥接模式 桥接模式也称为桥梁模式,是结构型设计模式之一.桥接模式中体现了"单一职责原则"."开闭原则"."里氏替换原则"."依赖倒置原则"等.同时它也是很实用的一种模式. 1.定义 将抽象部分与现实部分分离,使它们都可以独立地进行变化. 2.使用场景 (1)如果一个系统需要在构建的抽象化角色和具体角色之间增加更多的灵活性,避免在两个层次之间建立静态的继承联系. (2)对于那些不希望使用继承或因为多层次继承导致系统类