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ā)入門與進(jìn)階教程》、《Android通信方式總結(jié)》、《Android基本組件用法總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設(shè)計有所幫助。
- Android 通過Intent使用Bundle傳遞對象詳細(xì)介紹
- 在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)詳細(xì)介紹
相關(guān)文章
Android編程實現(xiàn)ListView滾動提示等待框功能示例
這篇文章主要介紹了Android編程實現(xiàn)ListView滾動提示等待框功能,結(jié)合實例形式分析了Android ListView滾動事件相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2017-02-02
Android學(xué)習(xí)教程之高仿安卓微信6.0(2)
這篇文章主要為大家詳細(xì)介紹了Android學(xué)習(xí)教程之高仿安卓微信6.0的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11
Android實現(xiàn)EditText內(nèi)容保存為Bitmap的方法
這篇文章主要介紹了Android實現(xiàn)EditText內(nèi)容保存為Bitmap的方法,涉及Android中saveBitmap方法的簡單使用技巧,需要的朋友可以參考下2016-01-01
如何使用Android實現(xiàn)接口實信息在留言板顯示
這篇文章主要介紹了如何使用Android接口實現(xiàn)信息的留言板顯示,需要的朋友可以參考下2015-07-07
Android發(fā)送GET與POST請求的DEMO詳解
本篇文章是對Android發(fā)送GET與POST請求的DEMO進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
Android實現(xiàn)強(qiáng)制下線功能的示例代碼
這篇文章主要介紹了Android實現(xiàn)強(qiáng)制下線功能的示例代碼,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07

