1、activity跳轉及傳值html
當進行activity之間的跳轉時咱們會遇到這樣的問題。首先熟悉下activity之間跳轉。Activity跳轉與傳值,主要是經過Intent類來鏈接多個Activity,以及傳遞數據。幾種跳轉方式可參照Android之Activity的幾種跳轉方式和Activity的跳轉與傳值,下面來講說開發時遇到的錯誤。android
一、Internal Server errorweb
在開發工程時,有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接口啊,或許是參數不對,抽完立刻查看,果真是這裏的問題,立馬給它傳個參數。post
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,果真調方法了,此問題完美解決。ui