UPDATEDオブジェクト:アンドロイド - レルムが
私は新しいクラスを作成し、のcompletコードチェック: TESTクラス:
import org.parceler.Parcel;
import io.realm.RealmObject;
import io.realm.TESTRealmProxy;
import io.realm.annotations.PrimaryKey;
@Parcel(implementations = {TESTRealmProxy.class},
value = Parcel.Serialization.BEAN,
analyze = {TEST.class})
public class TEST extends RealmObject {
@PrimaryKey
int Id;
String Name;
public int getId() {
return Id;
}
public String getName() {
return Name;
}
public TEST(){
}
public TEST(int id, String name){
this.Id = id;
this.Name = name;
}
}
Activity1:
Intent resultIntent = new Intent(this, NewActivity.class);
TEST dd = new TEST(2, "pa7");
Log.e(TAG, "Profile: "+dd.getId());
resultIntent.putExtra("userProfile",Parcels.wrap(dd));
startActivityForResult(resultIntent, 3);
NewActivity:
をTEST mUserd = Parcels.unwrap(getIntent().getParcelableExtra("userProfile"));
if(mProfileUserd != null) {
Log.e(TAG, "ID: USER: " + mUserd.getId()+" - name "+mUserd.getName());
} else {
Log.e(TAG, "Is Null");
}
OUTPUT:
Profile: 2
ID: USER: 0 - name null
OLD
Userクラス:
@Parcel(implementations = {
UserRealmProxy.class},
value = Parcel.Serialization.BEAN,
analyze = {User.class})
public class User extends RealmObject {
int Id;
String Name;
}
機能:
Intent resultIntent = new Intent(this, NewActivity.class);
resultIntent.putExtra("userProfile",Parcels.wrap(User.class, mAuthor));
startActivityForResult(resultIntent, 6);
NewActivity:
mUser = Parcels.unwrap((Parcelable) getIntent().getExtras().get("userProfile"));
私はUserというオブジェクトを持っていますが、1つのこと以外はすべて正常に動作します。私はデータベースからユーザーを要求する断片(B)を持っていますが、そのユーザーを領域に保存する必要はありません。私がこの断片で必要とするのは、ユーザオブジェクトを別のアクティビティに送ることだけです。
注:他のフラグメント(A)では、ユーザーを保存する必要がありますが、フラグメントBでは必要ありません。
私の質問:RealmObjectを拡張せず、フラグメントBで使用する「User2」という別のオブジェクトを作成する必要がありますか?または別の方法があります。
public class User extends RealmObject {
}
私はこれをチェックして、再度投稿します。あなたの答えをありがとう –
私のクラスにパーセルの実装を追加しました。私はRealmListConverterが必要とは思わないので、ただ1つのオブジェクトです。とにかく、どうやってオブジェクトを別のアクティビティに送ることができますか?次のようにする必要があります: resultIntent.putExtra( "user"、(Parcelable)mAuthor); –
私はそれがうまくいくはずです、あなたはそれを試してみるべきだと思います – EpicPandaForce