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

本文通过实例演示了如何使用Intent和Bundle实现两个Android应用程序之间的数据传递。具体展示了从一个应用发送包含频道名称的数据到另一个应用,并在接收端显示该频道名称的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android笔记——不同apk之间传递参数与数据
[url]http://dongyang555-126-com.iteye.com/blog/1308586[/url]

android编程的时候,有时候需要在不同的apk之间传递参数或数据,下面是一个简单的例子:
APK(1)的程序代码:
IntentSend.java:
package com.is; 

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

public class IntentSend extends Activity {
Channel channel = new Channel();
Button szws;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
szws = (Button)findViewById(R.id.szws);
szws.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v) {
Intent intent = new Intent();
Bundle bundle = new Bundle();
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 {
String channels[] = {
"深圳卫视",
"深圳电视剧",
"深圳都市"
};
}


APK(2)的程序代码:
IntentGet.java:
package com.ig;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class IntentGet extends Activity {
TextView info;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
info =(TextView)findViewById(R.id.info);
Bundle bundle = new Bundle();
bundle = this.getIntent().getExtras();

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

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


[color=red]好用[/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值