Android開發(fā)中Intent傳遞對象的方法分析
本文實例分析了Android開發(fā)中Intent傳遞對象的方法。分享給大家供大家參考,具體如下:
方法一:
利用方法:public Intent putExtra (String name, Parcelable value)傳遞一個Parceable的參數(shù),此方法的參數(shù)被序列化到內(nèi)存。
利用方法:public Intent putExtra (String name, Serializable value)傳遞一個實現(xiàn)了序列化接口類的對象,此方法的實參被序列化到磁盤。
方法二:
把數(shù)據(jù)存放到應(yīng)用程序的“Context”中,定義MyApplication類,讓其繼承Application類,在MyApplication中存入相關(guān)數(shù)據(jù)的引用。代碼如下:
import android.app.Application; import cn.itcast.mobilesafe.domain.TaskInfo; public class MyApplication extends Application { public TaskInfo tastInfo; }
在清單文件中配置Application:
<application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name="MyApplication"> <uses-library android:name="android.test.runner" />
將要存放的數(shù)據(jù)存入Application中:
Intent intent = new Intent(TaskManagerActivity.this, AppDetailActivity.class); MyApplication myApp = (MyApplication) getApplication(); Object obj = lv_task_manager.getItemAtPosition(position); if(obj instanceof TaskInfo){ TaskInfo info = (TaskInfo) obj; myApp.tastInfo = info; startActivity(intent); }
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)入門與進階教程》、《Android通信方式總結(jié)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android 通過Intent使用Bundle傳遞對象詳細介紹
- 在Android中通過Intent使用Bundle傳遞對象的使用方法
- Android中Intent傳遞對象的3種方式詳解
- 詳解Android中Intent傳遞對象給Activity的方法
- Android中Intent傳遞對象的兩種方法Serializable,Parcelable
- Android中使用Intent在Activity之間傳遞對象(使用Serializable或者Parcelable)的方法
- Android編程使用Intent傳遞對象的方法分析
- Android系列之Intent傳遞對象的幾種實例方法
- Android Intent傳遞對象的兩種方法(Serializable,Parcelable)詳細介紹
相關(guān)文章
Android 自定義SeekBar 實現(xiàn)分段顯示不同背景顏色的示例代碼
這篇文章主要介紹了Android 自定義SeekBar 實現(xiàn)分段顯示不同背景顏色,本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06Android布局ConstraintLayout代碼修改約束及輔助功能
這篇文章主要為大家介紹了Android布局ConstraintLayout代碼修改約束及輔助功能示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-09-09