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程序之间数据的传递。
分享到:
相关推荐
FPGA自学笔记——设计与验证公开版;十分适合初学者使用
Android学习笔记——获取网络图片并显示
Android开发笔记——模拟器、应用教程 pdf Android开发笔记——模拟器、应用教程 pdf
【第一部分】历史文章: Android学习笔记(一)——创建第一个Android项目 Android学习笔记(二)android studio基本控件及布局(实现图片查看器) ...Android学习笔记(七)——数据存储(共享参数Share
专题资料(2021-2022年)GIS学习笔记——地图投影与GPS参数计算要点.doc
Android学习笔记(十二)——使用意图传递数据的几种方式 完整代码
Cocos2d-x学习笔记——完全掌握C++ API与游戏项目开发.zip
Android开发笔记,内容涉及模拟器参数、进程与线程、Android 释放手机资源,进程释放优先级、分析HelloAndroid、添加编辑框与按钮、使用Intent启动另一个Activity、在不同Task中启动Activity、Intent与Intent ...
Android开发者学习笔记——View、Canvas、bitmap
网络运维笔记——T221.pdf网络运维笔记——T221.pdf网络运维笔记——T221.pdf网络运维笔记——T221.pdf网络运维笔记——T221.pdf网络运维笔记——T221.pdf网络运维笔记——T221.pdf网络运维笔记——T221.pdf网络运维...
网络运维笔记——T221.docx网络运维笔记——T221.docx网络运维笔记——T221.docx网络运维笔记——T221.docx网络运维笔记——T221.docx网络运维笔记——T221.docx网络运维笔记——T221.docx网络运维笔记——T221.docx
Android Training学习笔记——Navigation 参考源码,文章地址:http://blog.csdn.net/xroocky/article/details/50804762
——————————————————————————————————————————————
Solidworks学习笔记——随形变化.docxSolidworks学习笔记——随形变化.docxSolidworks学习笔记——随形变化.docxSolidworks学习笔记——随形变化.docxSolidworks学习笔记——随形变化.docxSolidworks学习笔记——...
遗传算法笔记——7.pdf遗传算法笔记——7.pdf遗传算法笔记——7.pdf遗传算法笔记——7.pdf遗传算法笔记——7.pdf遗传算法笔记——7.pdf遗传算法笔记——7.pdf遗传算法笔记——7.pdf
学习linux的笔记,发到博文了,鉴于文档方便...Linux笔记——shell补充:参数传递&函数等 Linux笔记——正则表达式入门及应用 Linux笔记——linux进程 Linux笔记——SVN命令总结 rpm&yum包管理命令总结 The end wklken
Android Training学习笔记——App Bar 参考源码,文章地址:http://blog.csdn.net/xroocky/article/details/50612401
Android Training学习笔记——Navigation 参考源码,文章地址:http://blog.csdn.net/xroocky/article/details/50767844