ANDROID开发之问题积累及解决方案(一)
一、activity跳转及传值
当进行activity之间的跳转时我们会遇到这样的问题。首先熟悉下activity之间跳转。Activity跳转与传值,主要是通过Intent类来连接多个Activity,以及传递数据。几种跳转方式可参照Android之Activity的几种跳转方式和Activity的跳转与传值,下面来说说开发时遇到的错误。
1、Internal Server error
在开发工程时,有6个activity,又新增一个activity,这个activity有listview,目的是从这个新增的activity点击item跳转到另外的6个activity,如下代码:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//这里做跳转,跳转到各自对应的页
switch (position) {
case 1:
openActivity(TariffMajorGoodsListActivity.class);
break;
case 2:
openActivity(TariffNativeDirectoryListActivity.class);
break;
case 3:
openActivity(TariffTaxRateListActivity.class);
break;
case 4:
openActivity(TariffCommentaryListActivity.class);
break;
case 5:
openActivity(ClassifyDecisionListActivity.class);
break;
case 6:
openActivity(ClassifyAdjudicationListActivity.class);
break;
default:
break;
}
}
protected void openActivity(Class<?> pClass) {
openActivity(pClass, null);
}
protected void openActivity(Class<?> pClass, Bundle pBundle) {
Intent intent = new Intent(this, pClass);
if (pBundle != null) {
intent.putExtras(pBundle);
}
startActivity(intent);
}
protected void openActivity(String pAction) {
openActivity(pAction, null);
}
protected void openActivity(String pAction, Bundle pBundle) {
Intent intent = new Intent(pAction);
if (pBundle != null) {
intent.putExtras(pBundle);
}
startActivity(intent);
}
然而,运行程序时,程序在点击跳转时报Internal Server error错误,直译为“内部服务器错误”,所以错就在Manifest.xml了,就让我们认识下它吧AndroidManifest.xml配置文件详解 ,仔细查看Manifest.xml,确认是正确的,这就纳闷了~~哪里的错了???顺手点了根烟,边抽边想,这个调的web接口啊,或许是参数不对,抽完马上查看,果然是这里的问题,立马给它传个参数。
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//这里做跳转,跳转到各自对应的页
Bundle mBundle = new Bundle();
Gson gson = new Gson();
switch (position) {
case 1:
MajorGoodsEntity majorGoodsEntity = new MajorGoodsEntity(null,datatotal,null,datatotal,null, null, null, null);
mBundle.putSerializable("majorGoods", majorGoodsEntity);
openActivity(TariffMajorGoodsListActivity.class,mBundle);
break;
case 2:
NativeDirectoryEntity directoryEntity = new NativeDirectoryEntity(null,datatotal);
mBundle.putSerializable("nativeDirectory", directoryEntity);
openActivity(TariffNativeDirectoryListActivity.class,mBundle);
break;
case 3:
TariffEntity queryEntity = new TariffEntity(null, datatotal,null, null, null, null, null, null, null, null);
mBundle.putSerializable("tariffQueryEntity", gson.toJson(queryEntity,TariffEntity.class));
openActivity(TariffTaxRateListActivity.class,mBundle);
break;
case 4:
TariffCommentaryItemEntity commentaryItemEntity = new TariffCommentaryItemEntity(null, datatotal, null, null,null);
mBundle.putSerializable("commentaryItemEntity",commentaryItemEntity);
openActivity(TariffCommentaryListActivity.class,mBundle);
break;
case 5:
ClassifyPublicationEntity entity =new ClassifyPublicationEntity("D",null, datatotal, null, null,null, null, null, null);
mBundle.putSerializable("conditionJSON", gson.toJson(entity, ClassifyPublicationEntity.class));
openActivity(ClassifyDecisionListActivity.class,mBundle);
break;
case 6:
ClassifyPublicationEntity entitys =new ClassifyPublicationEntity("R",null,datatotal,null,null,null,null,null, null);
mBundle.putSerializable("conditionJSON", gson.toJson(entitys, ClassifyPublicationEntity.class));
openActivity(ClassifyAdjudicationListActivity.class,mBundle);
break;
default:
break;
}
}
哈哈,这样一debug,果然调方法了,此问题完美解决。
ANDROID开发之问题积累及解决方案(一)的更多相关文章
- ANDROID开发之问题积累及解决方案(二)
错误:“Binary XML file line # : Error inflating class” 原因:此异常是布局文件中有错引起的,那么返回到布局文件中看看. <?xml version ...
- ANDROID开发之问题积累及解决方案(三)
1.dexDebug ExecException finished with non-zero exit value 2需要在gradle中配置下面的代码,原因是引用了多个libraries文件 de ...
- ANDROID开发之问题积累及解决方案(四)
首先贴出问题类型: 程序无法启动,查看logcat,提示如下信息: W/dalvikvm(679): PR_CAPBSET_DROP 32 failed: Invalid argument. Plea ...
- Android 开发有用代码积累
Android开发需求变化快,开发周期要求尽量短,接下来一系列文章从实际使用出发总结一些常用的代码片段,便于查找,也为后来人提供一份参考. 1.获取Manifest的基本信息(升级页面和软件关于页面一 ...
- 9种常见的Android开发错误及解决方案
整理总结了9个Android开发中的错误以及解决方案,共同探讨进步! 1. 如果你的项目的R文件不见的话,可以试下改版本号在保存,R文件不见一般都是布局文本出错导致. 2. 布局文件不可以有大写字母 ...
- Android开发——Android M(6.0) 权限解决方案
Android开发--Android M(6.0) 权限解决方案 自从Android M(6.0)发布以来,权限管理相比以前有了很大的改变,很多程序员发现之前运行的好好的Android应用在Andro ...
- Android 开发日常积累
Android 集合 Android 开源项目分类汇总 扔物线的 HenCoder 高级 Android 教程 hencoder HenCoder:给高级 Android 工程师的进阶手册 Andro ...
- Android开发——View滑动冲突解决方案
0. 前言 我们在Android开发--事件分发机制详解中深入学习了事件分发机制,为我们解决Android开发中的滑动冲突问题做了初步准备.针对滑动冲突这里给出两种解决方案:外部拦截法和内部拦截法 ...
- Android开发——常见的内存泄漏以及解决方案(二)
)Android2.3以后,SoftReference不再可靠.垃圾回收期更容易回收它,不再是内存不足时才回收软引用.那么缓存机制便失去了意义.Google官方建议使用LruCache作为缓存的集合类 ...
随机推荐
- Linux下创建新用户
useradd -h查询使用方法 useradd -g sysadmin -d /home/devops -m -c "DevOps Installation User" -s / ...
- Windows server 2012远程桌面会话主机和远程桌面授权,server2012
摘要:对于windows server2012服务器一般都是默认能够支持两用户远程登录,而通过安装远程桌面服务里的远程桌面会话主机和远程桌面授权,并对其进行配置,即可实现多用户远程登录. 远程桌面服务 ...
- (Hibernate进阶)Hibernate基本映射(三)
介绍Hibernate的经典内容:对象关系映射.主要介绍映射的基本概念,映射的分类,映射文件. 概念 ORM(Object Relational Mapping),即对象关系映射.它的作用就是在关系型 ...
- C#调用 ICSharpCode.SharpZipLib.Zip 实现解压缩功能公用类
最近想用个解压缩功能 从网上找了找 加自己修改,个人感觉还是比较好用的,直接上代码如下 using System; using System.Linq; using System.IO; using ...
- Docker指令集
FROM 语法:FROM <image>[:<tag>] 解释:设置要制作的镜像基于哪个镜像,FROM指令必须是整个Dockerfile ...
- VS2013不显示最近打开文件
首先点击开始在左下角输入"regedit" 右击HKEY_CURRENT_USER,点击查找,输入NoRecentDocsHistory 在右边找到NoRecentDocsHist ...
- WebService 用法
上文详细讨论了MQ的使用方法,MQ作为一种信息存储机制,将消息存储到了队列中,这样在做分布式架构时可以考虑将消息传送到MQ服务器上,然后开发相应的服务组件获取MQ中的消息,自动获取传送的 ...
- IO操作概念。同步、异步、阻塞、非阻塞
“一个IO操作其实分成了两个步骤:发起IO请求和实际的IO操作. 同步IO和异步IO的区别就在于第二个步骤是否阻塞,如果实际的IO读写阻塞请求进程,那么就是同步IO. 阻塞IO和非阻塞IO的区别在于第 ...
- js中的三元运算符
<script type="text/javascript"> var b=5; (b == 5) ? a="true" : a="fal ...
- 标识符,unicode和GBK
标识符Identifier 作用: —给变量,类,和方法命名 Java标识符有如下命名规则: —标识符必须以字母,下划线,美元符开头. —标识符其他部分可以是字母,下划线,美元符和数字的任意组合. — ...