Android 如何進行頁面傳遞對象


   當我們從一個頁面調到另一個頁面的時候,需要把該頁面的一些設定值也傳遞給下一個頁面。當要傳遞的值很多時,我們可以傳遞一個對象。

   頁面1:

Intent intent = new Intent(PageOneActivity.this, PageTwoActivity.class);
SoftwareProlemInfo info = softwareProlemInfos.get(position);

Bundle bundle = new Bundle();
bundle.putSerializable("softPro", info);
intent.putExtras(bundle);
startActivity(intent);

 頁面2:

 SoftwareProlemInfo softwareProlemInfo;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pagetwo);

        Intent intent  = this.getIntent();
        softwareProlemInfo = (SoftwareProlemInfo)intent.getSerializableExtra("softPro");
     ....
}
其中:SoftwareProlemInfo是一個Serializable化的類。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM