ANDROID開發之問題積累及解決方案(不斷更新)

來源:互聯網
上載者:User

標籤:

一、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開發之問題積累及解決方案(不斷更新)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.