Intent单例
来源:互联网 发布:linux怎么安装 编辑:程序博客网 时间:2024/06/05 03:08
public class IntentSingle{ //跳转的Intent private Intent intent; //广播Intent private Intent sendIntent; //bundle传值 private Bundle bundle; private static IntentSingle Instance = new IntentSingle(); private IntentSingle() { intent = new Intent(); sendIntent = new Intent(); bundle = new Bundle(); } public Bundle getBundle() { return bundle; } //获取单例对象 public static IntentSingle getInstance() { return Instance; } /** * 或取Intent传的值,只有int 类型和String类型(根据需求添加) * @param key */ public String getString(String key){ return intent.getStringExtra(key); } public int getInt(String key){ return intent.getIntExtra(key,0); } public String[] getStringArrayList(String key){ return intent.getStringArrayExtra(key); } public int[] getIntArrayList(String key){ return intent.getIntArrayExtra(key); } //跳转传值 public <T>void addActivity(Context moveContext, Class<T> tClass, Bundle bundle){ intent.setClass(moveContext,tClass); intent.putExtras(bundle); moveContext.startActivity(intent); } //跳转 public <T>void addActivity(Context moveContext,Class<T> tClass){ intent.setClass(moveContext,tClass); moveContext.startActivity(intent); } //发送广播传值 public void sendBroadCast(Context broadContext,String action, Bundle bundle){ sendIntent.setAction(action); sendIntent.putExtras(bundle); broadContext.sendBroadcast(sendIntent); } //发送广播 public void sendBroadCast(Context broadContext ,String action){ sendIntent.setAction(action); broadContext.sendBroadcast(sendIntent); }}
1 0
- Intent单例
- 使用单例模式封装Intent(实现跳转与携带数据跳转,顺带发送广播)
- android之从简单计算器看intent
- intent
- Intent
- Intent
- Intent
- intent
- Intent
- intent
- Intent
- Intent
- Intent
- Intent
- Intent
- Intent
- intent
- Intent
- 关于Tomcat启动报错:Failed to initialize end point associated with ProtocolHandler ["http-apr-8080"]
- Git 的 .gitignore 配置
- 十六进制转十进制
- 从头开始学java<五>
- Unix环境高级编程--多线程(一)
- Intent单例
- Java中的反射机制
- Android基础:Date & Time组件(上)
- 又是缓存惹的祸!!!
- C/C++调用Matlab函数
- Linux动态库添加
- wu
- JSP中脚本、声明和表达式的区别
- 开始新篇章--C语言编程-基于C Prime Plus