Android Open Source - android_bunble Main Activity






From Project

Back to project page android_bunble.

License

The source code is released under:

Apache License

If you think the Android project android_bunble 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.example.android_bunble;
//from   ww w  . j  a  v  a 2s . c o m
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity implements OnClickListener {

  private static final String TAG = "ykge";

  private Button mBtnBasic = null;
  private Button mBtnPar = null;
  private Button mBtnSer = null;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mBtnBasic = (Button) findViewById(R.id.btnBasic);
    mBtnBasic.setOnClickListener(this);

    mBtnPar = (Button) findViewById(R.id.btnPar);
    mBtnPar.setOnClickListener(this);

    mBtnSer = (Button) findViewById(R.id.btnSer);
    mBtnSer.setOnClickListener(this);

  }

  @Override
  public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btnBasic:
      //sendBasicDataThroughBundle();
      
      Intent intent = new Intent();  
      intent.setAction("Skywang_ACTION");  
      startActivity(intent);
      break;
    case R.id.btnPar:
      //sendParcelableDataThroughBundle();
//      Uri uri = Uri.parse("http://www.baidu.com/");
//      Intent intent2 = new Intent(Intent.ACTION_VIEW, uri);
//      startActivity(intent2);
      
      Uri uri = Uri.parse("file///sdcard/song.mp3");
      Intent it = new Intent(Intent.ACTION_VIEW); 
      it.setDataAndType(uri, "audio/mp3");
      startActivity(it);
      break;
    case R.id.btnSer:
      //sendSeriableDataThroughBundle();
      
      //sms
//      Uri uri2 = Uri.parse("smsto:15827617368");
//      Intent intent3 = new Intent(Intent.ACTION_SENDTO, uri2);
//      intent3.putExtra("sms_body", "text");
//      startActivity(intent3);
      
      Uri uri4 = Uri.parse("tel:12345678");
      Intent intent4 = new Intent(Intent.ACTION_DIAL, uri4);
      
      startActivity(intent4);
      break;
    default:
      break;

    }
  }
  
  // sent basic data, such as int, strin, etc...  through bundle
    private void sendBasicDataThroughBundle(){  
    // "com.test" is the package name of the destination class
    // "com.test.Activity02" is the full class path of the destination class
    Intent intent = new Intent().setClassName("com.example.android_bunble", "com.example.android_bunble.Bundle2");
    Bundle bundle = new Bundle();
    bundle.putString("name", "skywang");
    bundle.putInt("height", 175);
    intent.putExtras(bundle);
    
    startActivity(intent);

    // end current class
    finish();
  }
    
 // sent object through Pacelable
    private void sendParcelableDataThroughBundle(){  
    Intent intent = new Intent().setClassName("com.example.android_bunble", "com.example.android_bunble.Bundle2");

        Book mBook = new Book();
        mBook.setBookName("Android");
        mBook.setAuthor("ykge");
        mBook.setPublishTime(2013);

        Bundle mBundle = new Bundle();
        mBundle.putParcelable("ParcelableValue", mBook);
        intent.putExtras(mBundle);
          
        startActivity(intent);
    finish();
    }
    
 // sent object through seriable
    private void sendSeriableDataThroughBundle(){  
    Intent intent = new Intent().setClassName("com.example.android_bunble", "com.example.android_bunble.Bundle2");

    Person mPerson = new Person();
        mPerson.setName("ykge");
        mPerson.setAge(24);

        Bundle mBundle = new Bundle();
        mBundle.putSerializable("SeriableValue",mPerson);
        intent.putExtras(mBundle);
          
        startActivity(intent);
    finish();
    }

}




Java Source Code List

com.example.android_bunble.ActionDestination.java
com.example.android_bunble.Book.java
com.example.android_bunble.Bundle2.java
com.example.android_bunble.MainActivity.java
com.example.android_bunble.Person.java