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?
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity" >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/hello_world" />
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="141dp"
- android:text="转跳" />
- </RelativeLayout>
转跳界面Xml
[html] view plaincopyprint?
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity" >
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="我是第二屏界面" />
- </RelativeLayout>
[java] view plaincopyprint?
- package com.example.intent1;
- import android.os.Bundle;
- import android.app.Activity;
- import android.content.Intent;
- import android.view.Menu;
- import android.view.View;
- import android.widget.Button;
- public class MainActivity extends Activity {
- private Button button;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- button = (Button) this.findViewById(R.id.button1);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Intent intent = new Intent(MainActivity.this, Other.class);//创建Intent 对象
- startActivity(intent);//开启intent
- MainActivity.this.finish();//使当前Activity结束
- }
- });
- }
- }
Otner.java
[java] view plaincopyprint?
- package com.example.intent1;
- import android.app.Activity;
- import android.os.Bundle;
- import android.text.style.SuperscriptSpan;
- public class Other extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- setContentView(R.layout.other);
- }
- }
接下来看一看可以传递数据的Intent
[html] view plaincopyprint?
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity" >
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:text="传递" />
- <EditText
- android:id="@+id/edit"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:ems="10"
- android:text=" />
- </RelativeLayout>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context=".MainActivity" >
- <Button
- android:id="@+id/button1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:text="传递" />
- <EditText
- android:id="@+id/edit"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:ems="10"
- android:text="" />
- </RelativeLayout>
Other.xml
[html] view plaincopyprint?
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/textView1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="TextView" />
- <Button
- android:id="@+id/button2"
- android:gravity="center_horizontal"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="获取数据" />
- </LinearLayout>
java文件
[java] view plaincopyprint?
- package com.example.intent2;
- import android.os.Bundle;
- import android.R.integer;
- import android.app.Activity;
- import android.content.Intent;
- import android.view.Menu;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- public class MainActivity extends Activity {
- private Button button;
- private EditText info;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- button=(Button)this.findViewById(R.id.button1);
- info=(EditText)this.findViewById(R.id.edit);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Intent intent=new Intent(MainActivity.this,Other.class);//设置意图
- intent.putExtra("info", info.getText().toString());//为意图增加附加信息
- startActivity(intent);//开始意图
- MainActivity.this.finish();//终止当前Ativity
- }
- });
- }
- }
Other.java
[java] view plaincopyprint?
- package com.example.intent2;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class Other extends Activity {
- Intent intent;
- private Button button;
- private TextView text;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- super.setContentView(R.layout.other);
- button=(Button)this.findViewById(R.id.button2);
- text=(TextView)this.findViewById(R.id.textView1);
- intent=super.getIntent();//获取意图对象
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String info=intent.getStringExtra("info");//获取传递的数据
- text.setText(info);//显示数据
- }
- });
- }
- }
使用Intent传递并返回数据
借助Intent实现成人身高体重测试程序
采用BMI 法 体重指数 = 体重(公斤) 除 身高(米)的平方 kg/m2 正常体重 : 体重指数 = 18 - 25 超重 : 体重指数 = 25 - 30 轻度肥胖 : 体重指数 > 30 中度肥胖 : 体重指数 > 35 重度肥胖 : 体重指数 > 40
xml
[java] view plaincopyprint?
- package com.example.inten3;
- import android.os.Bundle;
- import android.app.Activity;
- import android.content.Intent;
- import android.view.Menu;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends Activity {
- private Button resetInfo,getInfo;
- private EditText height,weight;
- private TextView detail;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- super.setContentView(R.layout.activity_main);
- resetInfo=(Button)this.findViewById(R.id.button1);//重置信息按钮
- getInfo=(Button)this.findViewById(R.id.button2);//获取信息按钮
- height=(EditText)this.findViewById(R.id.editText1);//身高输入框
- weight=(EditText)this.findViewById(R.id.editText2);//体重输入框
- detail=(TextView)this.findViewById(R.id.textView3);//信息显示
- // 重置按钮的监听
- resetInfo.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- //将他们都设置为空
- weight.setText("");
- height.setText("");
- detail.setText("");
- }
- });
- // 获取信息按钮的监听
- getInfo.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Intent intent =new Intent(MainActivity.this, Other.class);//创建意图对象
- // 增加附加信息
- intent.putExtra("weight", Double.valueOf(weight.getText().toString()));
- intent.putExtra("height", Double.valueOf(height.getText().toString()));
- //设置启动并传递请求码
- startActivityForResult(intent, 1);
- }
- });
- }
- // 处理返回的信息
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- // TODO Auto-generated method stub
- switch (resultCode) {
- case RESULT_OK:
- //设置信息
- MainActivity.this.detail.setText(data.getStringExtra("endMsg"));
- break;
- default:
- break;
- }
- }
- }
- 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?
- package com.example.inten3;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class Other extends Activity {
- private Button returnMsg, resetbut;
- private TextView weightMsg, heightMsg;
- private Double weight, height;
- private String endMsg;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // TODO Auto-generated method stub
- super.onCreate(savedInstanceState);
- super.setContentView(R.layout.other);
- returnMsg = (Button) this.findViewById(R.id.Otherbutton1);
- resetbut = (Button) this.findViewById(R.id.Otherbutton2);
- weightMsg = (TextView) this.findViewById(R.id.OthertextView1);
- heightMsg = (TextView) this.findViewById(R.id.OthertextView2);
- // 获取意图对象
- Intent intent = super.getIntent();
- // 获得参数
- weight = intent.getDoubleExtra("weight", 0);
- height = intent.getDoubleExtra("height", 0);
- weightMsg.setText("您的体重:" + weight + "KG");
- heightMsg.setText("您的身高:" + height + "CM");
- returnMsg.setOnClickListener(new View.OnClickListener() {
- // 对传入的数据进项判断和处理
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- Double heightNum = height / 100;
- double endNum = weight / (heightNum * heightNum);
- if (endNum >= 18 && endNum <= 25) {
- endMsg = "您的身体很正常哦,继续保持亲。";
- } else if (endNum < 18) {
- endMsg = "亲啊,不能总是减肥啊,您现在可是偏瘦哦,当心身体";
- } else if (endNum > 25 && endNum <= 30) {
- endMsg = "您现在有一点胖哦,不过不要紧,要注意饮食哦";
- } else if (endNum > 30 && endNum <= 35) {
- endMsg = "亲,您已经进入肥胖人群 了哦,注意锻炼哦";
- } else if (endNum > 35) {
- endMsg = "额,你,你。。你怎么可以这样,还不赶快减肥,当心找不到对象哦";
- }
- // 将参数设置到intnet上
- Other.this.getIntent().putExtra("endMsg", endMsg);
- // 设置返回集,并设置返回接受码
- Other.this.setResult(RESULT_OK, Other.this.getIntent());
- // 将dangqianActivity结束掉
- Other.this.finish();
- }
- });
- // 重新输入监听
- resetbut.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- // 设置返回集合取消状态码
- Other.this.setResult(RESULT_CANCELED, Other.this.getIntent());
- // 结束当前Activity
- Other.this.finish();
- }
- });
- }
- }
学习了intent的基本用途,下节我们来学习Intent调用系统指令来完成一些其他操作
下节预报:Intent进阶
时间: 2024-11-06 04:31:59