Android Open Source - ramp_up_android Intents Activity






From Project

Back to project page ramp_up_android.

License

The source code is released under:

Apache License

If you think the Android project ramp_up_android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.macadamian;
/*from   ww w . j a v  a 2  s  .co m*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;

public class IntentsActivity extends Activity {
    static final String EXTRA_OPTION = "com.macadamian.intent.extra.OPTION";
    static final String EXTRA_RESULT = "com.macadamian.intent.extra.RESULT";

    static final String ACTION_RESULT = "com.macadamian.intent.action.RESULT";

    View.OnClickListener _click_listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch (v.getId()) {
                    case R.id.intents_start_activity:
                        send();
                        break;
                    case R.id.intents_start_activity_for_result:
                        send_for_result();
                        break;
                }
            }
        };
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.intents);        
        connect();
    }

    private void connect() {
        findViewById(R.id.intents_start_activity).setOnClickListener(_click_listener);
        findViewById(R.id.intents_start_activity_for_result).setOnClickListener(_click_listener);
    }

    private Intent make_intent() {
        Intent rv = new Intent(this, IntentsStartedActivity.class);
        rv.putExtra(EXTRA_OPTION, get_option());
        return rv;
    }

    private void send() {
        startActivity(make_intent());
    }

    static final int REQUEST_CODE = 1;

    private void send_for_result() {
        startActivityForResult(make_intent(), REQUEST_CODE);
    }

    private int get_option() {
        switch (((RadioGroup) findViewById(R.id.intents_selected_option)).getCheckedRadioButtonId()) {
            case R.id.intents_radio_option_a:
                return 0;
                
            case R.id.intents_radio_option_b:
                return 1;
        }
        return -1;
    }

    private void show_result(Intent i) {
        ((TextView) findViewById(R.id.intents_result)).setText(i.getStringExtra(EXTRA_RESULT));
    }

    @Override
    protected void onActivityResult(int code, int result, Intent i) {
        if (Activity.RESULT_OK == result) {
            switch (code) {
                case REQUEST_CODE:
                    show_result(i);
                    break;
            }
        }
    }
}




Java Source Code List

com.macadamian.ActionBarExampleActivity.java
com.macadamian.ActionsActivity.java
com.macadamian.BasicUserInterfaceActivity.java
com.macadamian.BroadcastsActivity.java
com.macadamian.CursorAdapterActivity.java
com.macadamian.DataExamplesFragment.java
com.macadamian.ExamplePreferenceFragment.java
com.macadamian.ExamplesSelectionActivity.java
com.macadamian.ExecutionControlExamplesFragment.java
com.macadamian.FragmentsActivity.java
com.macadamian.InAppBillingActivity.java
com.macadamian.IntentsActivity.java
com.macadamian.IntentsStartedActivity.java
com.macadamian.SimpleListAdapterActivity.java
com.macadamian.SystemExamplesFragment.java
com.macadamian.UserInterfaceExamplesFragment.java
com.macadamian.ViewPagerActivity.java
com.macadamian.billing.Base64DecoderException.java
com.macadamian.billing.Base64.java
com.macadamian.billing.IabException.java
com.macadamian.billing.IabHelper.java
com.macadamian.billing.IabResult.java
com.macadamian.billing.Inventory.java
com.macadamian.billing.Purchase.java
com.macadamian.billing.Security.java
com.macadamian.billing.SkuDetails.java