Activityフルジャンプ例

3384 ワード

例:
package com.cn;

import com.util.ProgressActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MycadillacActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button btn1 = (Button)findViewById(R.id.login);
        btn1.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				Intent intent1 = new Intent(MycadillacActivity.this,ProgressActivity.class);
				MycadillacActivity.this.startActivityForResult(intent1, 10);
			}
		});
    }
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		String name = data.getExtras().get("name").toString();
		System.out.println("requestCode:"+requestCode+"  resultCode:"+resultCode+"   name:"+name);
		super.onActivityResult(requestCode, resultCode, data);
	}
}
package com.util;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.cn.R;

public class ProgressActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.progress);
		super.onCreate(savedInstanceState);
		Button btn1 = (Button)findViewById(R.id.button1);
		btn1.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent i = new Intent();
				i.putExtra("name", "11");
				ProgressActivity.this.setResult(5, i);
				ProgressActivity.this.finish();
			}
		});
	}
}

AndroidManifestでxmlの2つのactivity.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.cn"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="8" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".MycadillacActivity"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
		<activity android:name="com.util.ProgressActivity"  android:theme="@android:style/Theme.Dialog"></activity>
    </application>
</manifest>