Android 初识Intent

news/2024/7/17 10:37:06
Android 初识Intent
ContractedBlock.gif ExpandedBlockStart.gif View Code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation
="vertical"
android:layout_width
="fill_parent"
android:layout_height
="fill_parent"
>
<Button
android:id="@+id/button1"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:text
="@string/button1"
/>
</LinearLayout>

ContractedBlock.gif ExpandedBlockStart.gif View Code
package com.Neddy;

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;
import android.widget.Toast;

public class MainActivity extends Activity
{
private Button button=null;
private final static int REQUEST_CODE=1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button
=(Button)findViewById(R.id.button1);
button.setOnClickListener(listener);
}

private OnClickListener listener=new OnClickListener()
{
public void onClick(View v)
{
// Intent intent=new Intent();
// intent.setAction(Intent.ACTION_SENDTO);
// intent.setData(Uri.parse("smsto:5554"));
// intent.putExtra("sms_body", "Welcome to ...");
// startActivity(intent);
Intent intent=new Intent();
intent.setClass(MainActivity.
this,SecondActivity.class);
intent.putExtra(
"str", "HI,hello world!");
// startActivity(intent);
startActivityForResult(intent, REQUEST_CODE);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode==REQUEST_CODE)
{
if(resultCode==SecondActivity.RESULT_CODE)
{
Bundle bundle
=data.getExtras();
String str
=bundle.getString("back");
Toast.makeText(MainActivity.
this,str,Toast.LENGTH_LONG).show();
}

}
}

}
ContractedBlock.gif ExpandedBlockStart.gif View Code
package com.Neddy;

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;
import android.widget.TextView;

public class SecondActivity extends Activity
{
private TextView second=null;
private Button button2=null;
final static int RESULT_CODE=1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Intent intent
=getIntent();
Bundle bundle
=intent.getExtras();
String str
=bundle.getString("str");
second
=(TextView)findViewById(R.id.second);
second.setText(str);

button2
=(Button)findViewById(R.id.button2);

button2.setOnClickListener(listener);

}

private OnClickListener listener=new OnClickListener()
{
public void onClick(View v)
{
Intent intent
=new Intent();
intent.putExtra(
"back", "Back Data");
setResult(RESULT_CODE,intent);
finish();
}
};

}
ContractedBlock.gif ExpandedBlockStart.gif View Code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package
="com.Neddy"
android:versionCode
="1"
android:versionName
="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<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=".SecondActivity"
android:label
="Second">
</activity>

</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
</manifest>

posted on 2011-09-10 10:06  Neddy11 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/Neddy/archive/2011/09/10/2173014.html


http://www.niftyadmin.cn/n/3297190.html

相关文章

WinForm资料

WinForm资料 2010-01-21 16:13:31| 分类&#xff1a; winform C# | 标签&#xff1a; |字号大中小 订阅 该系列主要整理收集在使用C#开发WinForm应用文章及相关代码, 平时看到大家主要使用C#来开发Asp.Net应用,这方面的文章也特别多,而关于WinForm的文章相对少很多,而自己对…

Java多线程同步器

转自&#xff1a; http://www.talentdigger.cn/home/space.php?uid2189&dothread&id4129 --------------------------------------------我是分割线----------------------------------- CyclcBarrier   在实际应用中&#xff0c;有时候需要多个线程同时工作以完成同…

xp_cmdshell

以操作系统命令行解释器的方式执行给定的命令字符串&#xff0c;并以文本行方式返回任何输出。语法xp_cmdshell {command_string} [, no_output]参数command_string是在操作系统命令行解释器上执行的命令字符串。no_output是可选参数&#xff0c;表示执行给定的 command_string…

【转】养成一个SQL好习惯带来一笔大财富

我们做软件开发的&#xff0c;大部分人都离不开跟数据库打交道&#xff0c;特别是erp开发的&#xff0c;跟数据库打交道更是频繁&#xff0c;存储过程动不动就是上千行&#xff0c;如果数据量大&#xff0c;人员 流动大&#xff0c;那么我么还能保证下一段时间系统还能流畅的运…

[公告]计划今晚19:00~20:00进行网站程序升级

计划今晚19:00~20:00对网站程序进行升级&#xff0c;届时可能不能正常访问博客园&#xff0c;请谅解由此给您带来的麻烦! 转载于:https://www.cnblogs.com/cmt1/archive/2006/03/15/350659.html

别了,攀枝花

<<别了&#xff0c;攀枝花 >> ——代腾飞 2005&#xff0d;01&#xff0d;27 于攀枝花 别了&#xff0c;攀枝花&#xff0c;我曾在此流浪了3个月的攀枝花&#xff0c;在此为了人生理想而努力奋斗了3个月的攀枝花&#xff0c;给我人生流浪的足迹留下了深深的脚印的…

sql执行过程超问题分析

sql执行过程超问题分析druid timeout设置mybatis timeout设置spring timeout设置haproxy timeout设置mycat timeout设置mysql timeout设置os timeout设置每一个过程都可能是导致原因。 目前项目报这个异常&#xff0c;一层层排查&#xff0c;结果haproxy 设置一分钟超时。 场…

java显示日历 插件_JAVA里 怎么用日期控件 在Grid里显示这个月的1-31号

展开全部日期类DateJava在日期类中封装了有关日期和时62616964757a686964616fe59b9ee7ad9431333236613432间的信息&#xff0c;用户可以通过调用相应的方法来获取系统时间或设置日期和时间。Date类中有很多方法在JDK1.0公布后已经过时了&#xff0c;在8.3中我们将介绍JDK1.0中新…