主要是传值的问题,intent的主要用途是发送广播、动作之类的,在创建该对象的时候把自己需要传递的值传到下一个intent就行了。如果说是两个activity的话,比如activity A 和 activity B,当你从 A 跳到 B 的时候,不要将 A finish掉,在 A 里面需要有onActivityResult 这个方法,从 A 跳到 B 的时候使用 startActivityForResult 这个方法就行了,具体怎么使用楼主去查一下api
可以的,传递的数据都放到intent中就好了
public class Activity01 extends Activity { private static final String TAG="Activity01"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Log.v(TAG,"onCreate");
Button button_exit=(Button)findViewById(R.id.exit); button_exit.setOnClickListener(new Button.OnClickListener(){ public void onClick(View v){ Activity01.this.finish(); } }); } public class Activity02 extends Activity { //private static final String TAG="Activity01"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity02); //Log.v(TAG,"onCreate");
private static final String TAG="Activity01";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.v(TAG,"onCreate");
Button button_next=(Button)findViewById(R.id.next);
button_next.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Intent intent=new Intent();
intent.setClass(Activity01.this, Activity02.class);
startActivity(intent);
Activity01.this.finish();
}
});
Button button_exit=(Button)findViewById(R.id.exit);
button_exit.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Activity01.this.finish();
}
});
}
public class Activity02 extends Activity {
//private static final String TAG="Activity01";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity02);
//Log.v(TAG,"onCreate");
Button button_before=(Button)findViewById(R.id.before);
button_before.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
Intent intent=new Intent();
intent.setClass(Activity02.this, Activity01.class);
startActivity(intent);
Activity02.this.finish();
}
});
}
}<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="这是第二个Activity。"
/>
<Button android:id="@+id/before"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity01"
/></LinearLayout>
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<Button android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Activity02"
/>
<Button android:id="@+id/exit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Exit"
/></LinearLayout>复制,粘贴,导入需要的包,就可以了。你感受下。