Start a new topic

How to update a row in existing collection?

Hello, I am new Kinvey User. I am using kinvey for developing android apps. I have to update or edit a row in to my existing collection.. so plz help how can i impliment this..


please provide me save code..... i asking for sample code.. plz.


Thanks.

according to you ...


 

private void saveProjectDetail() {
		
		ProjectEntity projectEntity = new ProjectEntity();
		AsyncAppData<ProjectEntity> myData = kinveyClient.appData("ProjectMaster", ProjectEntity.class);
		myData.getEntity(id, new KinveyClientCallback<ProjectEntity>() {
		    
			@Override
		    public void onSuccess(ProjectEntity project) { 
			
				project.setProjectName(et_projectName.getText().toString());
				project.setFromDate(et_fromDate.getText().toString());
				project.setTeamSize(et_teamSize.getText().toString());
				project.setVersion(et_version.getText().toString());
				project.setDesc(et_desc.getText().toString());
				
				AsyncAppData<ProjectEntity> savedata=kinveyClient.appData("ProjectMaster", ProjectEntity.class);
				savedata.save(project, new KinveyClientCallback<ProjectEntity>() {

					@Override
					public void onFailure(Throwable t) {
						// TODO Auto-generated method stub
						Log.v(TAG, "Failed to save ", t);
					}

					@Override
					public void onSuccess(ProjectEntity p) {
						// TODO Auto-generated method stub
						Log.v(TAG, "saved "+ p.getActionId());
					}
				});
				Log.v(TAG, "received "+ project.getProjectName());
		    }
			@Override
		    public void onFailure(Throwable error) { 
		        Log.e(TAG, "failed to fetchByFilterCriteria", error);
		    }
		});
	}

 

i attached a file of logcat... the exception thown by server.. 


plz look at this..


Thanks,

txt
(8.69 KB)

please tell me this the right credentials or not

Sukhpal: 


The credentials should be your application id (starts with kid_ and can be found in the console when you log in in the upper right corner) and your secret should be immediately next to the app id.


The way that I build the client is something like this:


 public static final String appKey = "<ID GOES HERE>";

 public static final String mySecret = "<Secret Goes Here>";


Client myAndroidClient = new Client.Builder(appKey, mySecret).build();



In your code it appears as though you're just using the base kinveyClient which won't contain any type of authentication.  By instantiating myAndroidClient with these credentials, and using it in place of kinveyClient() you should see your issue resolved.


Thanks.

Hey Damien Bell,


I am facing same problem.. insufficient credentials.. please look through my code 


 

private void saveUserDetail() {
		
		final Client mkinveyClient = new Client.Builder(appKey, mySecret,getActivity()).build();
		LoginEntity userEntity = new LoginEntity();
		AsyncAppData<LoginEntity> myData = kinveyClient.appData("LoginMaster", LoginEntity.class);
		myData.getEntity(id, new KinveyClientCallback<LoginEntity>() {
		    
			@Override
		    public void onSuccess(LoginEntity user) { 
				
				user.setFirstName(et_firstname.getText().toString());
				user.setLastName(et_lastname.getText().toString());
				user.setEmail(et_Email.getText().toString());
				user.setUsername(et_Username.getText().toString());
				user.setRole(spr_Role.getSelectedItem().toString());
				user.setProjectName(spr_Projects.getSelectedItem().toString());
				
				AsyncAppData<LoginEntity> update=mkinveyClient.appData("LoginMaster", LoginEntity.class);
				
				update.save(user, new KinveyClientCallback<LoginEntity>() {

					@Override
					public void onFailure(Throwable t) {
						Log.e(TAG, "failed update", t);
					}

					@Override
					public void onSuccess(LoginEntity u) {
						Log.v(TAG, "update "+ u.getEmail());
					}
				});
				Log.v(TAG, "received "+ user.getEmail());
		    }
			
			@Override
		    public void onFailure(Throwable error) { 
		        Log.e(TAG, "failed to fetchByFilterCriteria", error);
		    }
		});
	}
	

 

On line 5 you use kinveyClient rather than mkinveyClient that you made on line 3.


Thanks,

Thanks guys, your solution worked for me as well

Login or Signup to post a comment