2010-07-02 94 views

回答

2

使用意向

Bundle extras = new Bundle(); 
extras.putString("my.unique.extras.key", "this is my message"); 
myIntent.putExtras(extras); 

putExtras(Bundle)方法然后在Intent您检索的额外

Bundle extras = this.getIntent().getExtras(); 
if (extras != null) { 
    if (extras.containsKey("my.unique.extras.key")) { 
    this.setTitle(extras.getString("my.unique.extras.key")); 
    } 
} 

这是一个duplicate question

0

意图可以包含数据。这些数据可以被接收组件使用。有两种类型的意向

  • 明确意图

  • 隐性意图

,并告知系统隐含的意图,他们可以处理,活动,服务和广播接收机可以有一个或多个意图过滤器。 有下意向滤波器三个测试这些是

  • 动作试验

  • 类别测试

  • 数据测试

    类从一个发送消息活动另一个使用意图和意图过滤器

    public class MessageActivity extends Activity { 
    
        public void onCreate(Bundle savedInstanceState) { 
    
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.message); 
        Intent i = new Intent(Intent.ACTION_VIEW); 
        i.setData(Uri.parse("sms:")); 
        startActivity(i); 
        }} 
    

    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:layout_width="match_parent" 
        android:layout_height="wrap_content"/> 
        </LinearLayout> 
    

这里我们使用隐式意图,所以我们必须在赋予权限的AndroidManifest.xml文件

<uses-permission android:name="android.permission.MESSAGE" /> 

和注册Message类内部应用

<activity android:name=".MessageActivity" > 
    <intent-filter> 
    <action android:name="android.intent.action.MESSAGE" /> </intent-filter> 

     </activity>