As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
I've created an app containing multiple databases and I need to use Kinvey for maintaining this data. Currently, I'm storing all the data locally using sqlite. When I'm not trying to use Cache and Offline, the data is written properly to the Kinvey database...I can verify this through the web console. When I try to add the lines for cache and offline policy, nothing gets written to Kinvey db and I get an error similar to what is shown below. This is just part of the logcat error. There appears to be some problem with offline user login?? I included some simple code below that reproduces the problem I'm having. I've read the guides on the website many times, and I just seem to be overlooking something. I added the services and permission to manifest as the guide stated. I don't know what else to try or where else to go. Any ideas as to what I'm doing wrong? Thanks.
gear.setOffline(OfflinePolicy.LOCAL_FIRST, new SqlLiteOfflineStore(this));
kinveyClient.user().login(username, password, new KinveyUserCallback() {
@Override
public void onFailure(Throwable arg0) {
}
@Override
public void onSuccess(User arg0) {
}
});
MyEntity event = new MyEntity();
event.setTitle("Launch Party");
gear.save(event, new KinveyClientCallback() {
@Override
public void onFailure(Throwable arg0) {
}
@Override
public void onSuccess(MyEntity arg0) {
Toast.makeText(getApplicationContext(),
"Object saved is: " + arg0.getTitle(),
Toast.LENGTH_LONG).show();
}
});
kinveyClient.user().logout().execute();
1 Comment
E
Edward
said
almost 10 years ago
Hey--
The library maintains the current user for you once they have successfully logged in once. When you use the `Client.Builder`class to create a client, it will automatically check if there is a previously logged in user, and if there is will attempt to login. Note that if you change the password of the user or invalidate their auth token, this auto-login will fail and the user will have to log in again.
You can call: myClient.user().isUserLoggedIn(), which returns true or false, to determine if you need to actually call login again.
OK, so with that in mind, the offline sync will use whatever credentials are stored on disk. This means that when a user logs in (they must be online for the first time ever that they login!) their credentials will be stored on the device, and then they can go offline and queue up requests. Once a connection is restored these credentials will be loaded from disk and used to authenticate the requests being executed in the background.
SO,
get rid of this line: kinveyClient.user().logout().execute();
and it should work for ya! When you perform a logout we are removing the credentials on disk, and cleaning up the offline queue and store for security purposes. Without credentials, you are getting that error message.
And thanks for the feedback. We are constantly iterating and trying to improve both our service, documentation, and interfaces. It can be challenging, and honestly, it's great to hear feedback from users. Documentation is challenging because we need to provide all the necessary information without overwhelming people, as there is a lot that people can do with a Kinvey backend. Still, we are trying, so don't hesitate to let us know if you have any more concerns or frustrations.
Mark Thrasher
01-20 15:42:15.257: E/SQLiteDatabase(6992): Error inserting _json={"Title":"Launch Party","_id":"5e8684e321664fa797f4d1cf53f55082"} _deleted=0 _id=5e8684e321664fa797f4d1cf53f55082 _user=null
01-20 15:42:15.257: E/SQLiteDatabase(6992): android.database.sqlite.SQLiteConstraintException: offline_myCollection._user may not be NULL (code 19)
AsyncAppData gear = kinveyClient.appData("myCollection",
MyEntity.class);
gear.setCache(new InMemoryLRUCache(), CachePolicy.CACHEFIRST);
gear.setOffline(OfflinePolicy.LOCAL_FIRST, new SqlLiteOfflineStore(this));
kinveyClient.user().login(username, password, new KinveyUserCallback() {
@Override
public void onFailure(Throwable arg0) {
}
@Override
public void onSuccess(User arg0) {
}
});
MyEntity event = new MyEntity();
event.setTitle("Launch Party");
gear.save(event, new KinveyClientCallback() {
@Override
public void onFailure(Throwable arg0) {
}
@Override
public void onSuccess(MyEntity arg0) {
Toast.makeText(getApplicationContext(),
"Object saved is: " + arg0.getTitle(),
Toast.LENGTH_LONG).show();
}
});
kinveyClient.user().logout().execute();