利用 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 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);
}
}
更多精彩
赞助商链接