Android笔记——不同apk之间传递参数与数据

android编程的时候,有时候需要在不同的apk之间传递参数或数据,下面是一个简单的例子:

APK(1)的程序代码:

IntentSend.java:

packagecom.is;

importandroid.app.Activity;

importandroid.content.Intent;

importandroid.os.Bundle;

importandroid.view.View;

importandroid.widget.Button;

publicclassIntentSendextendsActivity{

Channelchannel=newChannel();

Buttonszws;

/**Calledwhentheactivityisfirstcreated.*/

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

szws=(Button)findViewById(R.id.szws);

szws.setOnClickListener(newButton.OnClickListener(){

publicvoidonClick(Viewv){

Intentintent=newIntent();

Bundlebundle=newBundle();

bundle.putString("channel",channel.channels[0]);

intent.setClassName("com.bget","com.bget.BinderGET");

intent.putExtras(bundle);

startActivity(intent);

}

});

}

}

Channel.java:

 package com.is;

public class Channel {

Stringchannels[]={

"深圳卫视",

"深圳电视剧",

"深圳都市"

};

}
APK(2)的程序代码:
IntentGet.java:
package com.ig;
import android.app.Activity;

importandroid.os.Bundle;

import android.widget.TextView;
public class IntentGet extends Activity {

TextViewinfo;

/**Calledwhentheactivityisfirstcreated.*/

@Override

publicvoidonCreate(BundlesavedInstanceState){

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

info=(TextView)findViewById(R.id.info);

Bundlebundle=newBundle();

bundle=this.getIntent().getExtras();

info.setText("现在播放的是:"+bundle.getString("channel"));

}

}
程序中,主要是调用了Intent和Bundle的方法,Intent程序之间的跳转,Bundle程序之间数据的传递。

相关推荐