I followed this guide on the Kinvey website and now have something this in my MainActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Client mKinveyClient = new Client.Builder(this.getApplicationContext()).build();
final AsyncAppData<MyEntity> ad = mKinveyClient.appData("myCollection", MyEntity.class);
ad.setCache(new InMemoryLRUCache(), CachePolicy.CACHEFIRST);
ad.setOffline(OfflinePolicy.LOCAL_FIRST, new SqlLiteOfflineStore<MyEntity>(this));
MyEntity event = new MyEntity();
event.setName("Launch Party");
event.setAddress("Kinvey HQ");
ad.save(event, new KinveyClientCallback<MyEntity>() {
@Override
public void onFailure(Throwable e) {
Log.e("TAG", "failed to save event data", e);
}
@Override
public void onSuccess(MyEntity r) {
Log.d("TAG", "saved data for entity "+ r.getName());
ad.get(new KinveyListCallback<MyEntity>() {
@Override
public void onSuccess(MyEntity[] result) {
Log.v("TAG", "received "+ result.length + " events");
}
@Override
public void onFailure(Throwable error) {
Log.e("TAG", "failed to fetch all", error);
}
});
}
});
}
Now if the phone is online and I do start the app several times I get the following output:
V/TAG﹕ received 0 events
V/TAG﹕ received 1 events
V/TAG﹕ received 2 events
V/TAG﹕ received 3 events
...
But if I activate the airplane mode to simulate offline usage:
V/TAG﹕ received 3 events
V/TAG﹕ received 3 events
V/TAG﹕ received 3 events
V/TAG﹕ received 3 events
...
As you can see the AppData won't get the recently saved entities while beeing offline. Do I get something wrong or is this kind of caching not possible?