ComponentName组件实现两个应用间传递

 

ComponentName组件实现两个应用间传递

分类: android技术总结   555人阅读  评论(0)  收藏  举报

package com.test;


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

public class TestActivity extends Activity implements OnClickListener{
 Button b1,b2,b3;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.comein);
        findView();
        bindView();
    }
 public void findView(){
     b1 = (Button) findViewById(R.id.button3);
     b2 = (Button) findViewById(R.id.button2);
     b3 = (Button) findViewById(R.id.button1);
     
    }
 private void bindView() {
  b1.setOnClickListener(this);
  b2.setOnClickListener(this);
  b3.setOnClickListener(this);
  
 }
 @Override
 public void onClick(View v) {
  switch (v.getId()) {
  case R.id.button2:
   Intent i1 = new Intent(Intent.ACTION_MAIN);
   i1.addCategory(Intent.CATEGORY_LAUNCHER);            
   ComponentName cn1 = new ComponentName("com.jy","com.jy.LogoActivity"); 
   i1.setComponent(cn1);
   Bundle bundle1 = new Bundle();
   
   bundle1.putString("username", "test");
   bundle1.putString("password", "test");
   bundle1.putString("vehicelId", "402880861270516b0112740db2260115");
   bundle1.putString("brand", "北京吉普");
   bundle1.putString("vehicl", "切诺基BJ6420EA");
   i1.putExtras(bundle1);
   startActivity(i1);

   break;
  case R.id.button1:
   Intent i2 = new Intent(Intent.ACTION_MAIN);
   i2.addCategory(Intent.CATEGORY_LAUNCHER);            
   ComponentName cn2 = new ComponentName("com.jy","com.jy.LogoActivity"); //第一个参数是另外一个应用的包名,也是主配置文件Manifest里设置好的包名 第二个是类名,要带上包名


   i2.setComponent(cn2);
   Bundle bundle2 = new Bundle();
   
   bundle2.putString("username", "test");
   bundle2.putString("password", "test");
   i2.putExtras(bundle2);
   startActivity(i2);
   break;
  case R.id.button3:
   
   
   Intent i3 = new Intent(Intent.ACTION_MAIN);
   i3.addCategory(Intent.CATEGORY_LAUNCHER);            
   ComponentName cn3 = new ComponentName("com.jy","com.jy.LogoActivity");            
   i3.setComponent(cn3);
   startActivity(i3);
   break;
  default:
   break;
  }
 }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值