Passing a KiiObject between Activities
The KiiUser
class and the KiiObject
class can be passed, for example, by using the Intent
class in Android because those classes implement the Parcelable
interface.
For example, you can pass a KiiObject
instance to another activity with the sample code below. You can pass a KiiUser
instance in a similar way.
This code passes a KiiObject.
// Create a KiiObject in an application-scope bucket.
KiiObject sendObject = Kii.bucket("mydata").object();
// Set key-value pairs to the KiiObject.
sendObject.set("score", 987);
sendObject.set("mode", "easy");
sendObject.set("premiumUser", false);
// Put the KiiObject to an intent.
Intent intent = new Intent(this, ReceiverActivity.class);
intent.putExtra("object", sendObject);
// Send the intent.
startActivity(intent);
This code receives a KiiObject.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_receiver);
// Receive a KiiObject with the getParcelableExtra() method.
KiiObject receivedObject = getIntent().getParcelableExtra("object");
// Get key-value pairs.
int score = receivedObject.getInt("score");
String mode = receivedObject.getString("mode");
boolean premiumUser = receivedObject.getBoolean("premiumUser");
}