[英]Pass RealmQuery object to Activity using Intent
我有一個創建RealmQuery<E>
的Activity
,我需要將此查詢傳遞給另一個Activity
以執行它。 我無法使用Intent
進行此操作,因為我要傳遞的對象不可包裹。 如何做到這一點?
可以使用Intent Extra實現來回傳遞數據Activity
。
您可以簡單地執行以下操作
首次Activity
首先將數據獲取為數據類型的變量
String uid = myModel.getUid();
將數據發送到ChefProfile
類
Intent intent = new Intent(MainActivity.this, ChefProfile.class);
intent.putExtra(ChefProfile.EXTRA_USER_ID, uid);
startActivity(intent);
現在讓我們從Intent中獲取數據,因為它已經到達了調用活動
這是Chef_Profile
類。 首先,我們必須為到達的數據創建一個常量字段。
private static final String EXTRA_USER_KEY = "uid";
//Here we obtain the data sent from first activity and extract it into userId
userId = getIntent().getStringExtra(EXTRA_USER_KEY);
if (userId == null) {
throw new IllegalArgumentException("Must pass EXTRA_POST_KEY");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.