WEB开发网
开发学院手机开发Android 开发 利用 Bundle 实现 Android Activity 间消息的传递... 阅读

利用 Bundle 实现 Android Activity 间消息的传递

 2010-03-25 17:06:00 来源:WEB开发网   
核心提示:}}package com.ray.test;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.MotionEvent;public class TestBundl

}

}

package com.ray.test;

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.view.MotionEvent;

public class TestBundle extends Activity {

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

}

public boolean onTouchEvent(MotionEvent event) {

Intent intent = new Intent();

intent.setClass(TestBundle.this, Target.class);

Bundle mBundle = new Bundle();

mBundle.putString("Data", "ray'blog");//压入数据

intent.putExtras(mBundle);

startActivity(intent);

finish();

return super.onTouchEvent(event);

}

}

将要跳转到的活动代码:

Java代码

package com.ray.test;

import android.app.Activity;

import android.os.Bundle;

public class Target extends Activity{

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Bundle bundle = getIntent().getExtras();

String data=bundle.getString("Data");//读出数据

setTitle(data);

}

}

package com.ray.test;

import android.app.Activity;

import android.os.Bundle;

public class Target extends Activity{

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Bundle bundle = getIntent().getExtras();

String data=bundle.getString("Data");//读出数据

setTitle(data);

}

}

上一页  1 2 3 4 

Tags:利用 Bundle 实现

编辑录入:coldstar [复制链接] [打 印]
赞助商链接