android应用开发详解(十四)--------------Intent的Action属性(续)
来源:互联网 发布:淘宝网卖家信用高流量 编辑:程序博客网 时间:2024/05/29 03:35
1、工程目录
2、MainActivity.java
package com.example.test_intent_action;import android.os.Bundle;import android.app.Activity;import android.content.Intent;import android.view.Menu;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class MainActivity extends Activity {private Button myBtn;private static final String MY_ACTION = "com.example.test_intent_action.MY_ACTION";@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);myBtn = (Button) findViewById(R.id.button01);myBtn.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubIntent intent = new Intent();// intent.setAction(MY_ACTION);// 下面两句是一起的intent.setAction(Intent.ACTION_GET_CONTENT);intent.setType("vnd.android.cursor.item/phone");startActivity(intent);}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
MyActivity.java
package com.example.test_intent_action;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.widget.TextView;public class MyActivity extends Activity{private TextView myText;@Overrideprotected void onCreate(Bundle savedInstanceState) {// TODO Auto-generated method stubsuper.onCreate(savedInstanceState);setContentView(R.layout.mylayout);myText=(TextView)findViewById(R.id.textview01);Intent intent = getIntent();String action = intent.getAction();myText.setText(action);}}3、布局文件
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <Button android:id="@+id/button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Activity的Action属性测试"/></LinearLayout>
mylayout.xml
<?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/textview01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /></LinearLayout>
4、结果演示
0 0
- android应用开发详解(十四)--------------Intent的Action属性(续)
- android应用开发详解(十四)------------------Intent的ComponentName属性
- android应用开发详解(十四)------------------------action属性(续)
- android应用开发详解(十四)----------------Intent的Category属性(续)
- android应用开发详解(十四)-------------Intent的Extras属性(续)
- [Android基础]Intent用法的二三事(上)——Componet、Action、Category的属性详解
- Intent的Component,Action和Category属性详解-android学习之旅(五十)
- Android开发之内置Intent.Action详解
- Android开发之Intent.Action详解
- android Intent的Action、Category属性
- Android Intent action详解
- Android Intent Action详解
- Android intent 属性详解(一)
- Android intent 属性详解(二)
- Android应用接收开机广播(android.intent.action.BOOT_COMPLETED)失败的原因
- Android开发--Intent-filter属性详解
- Android开发--Intent-filter属性详解
- Android开发--Intent-filter属性详解
- new, delete 的用法
- HDU 2425-Hiking Trip(BFS+优先队列)
- protel 99se 中间区域不敷铜
- 关于ArrayList与数组对象的直接输出
- 2034 人见人爱A-B
- android应用开发详解(十四)--------------Intent的Action属性(续)
- 9.19 工程日志
- HDU 1086 You can Solve a Geometry Problem too 判断任意两线段是否相交
- uva10245The Closest Pair Problem
- 局部变量地址的返回
- @RequestBody应用
- [Amazon笔试]求比数n大的最小回文数的字符串形式
- 怎么使float保留两位小数或多位小数
- sublime使用笔记