0

sorry if this is a dummy question, but I am quite new coding in Android and using the Google Drive API.

In my app, I need to create a file within a folder I previously created. At the time that the folder is created, I can only retrieve the DriveID using DriveId.encodeToString. So, in order to get the ResourceID for the creation of the file in that folder, I have implemented the following code. Although the code is working, this code never returns to the previous activity.

Could anyone help me and explain the reason? I suspect that it should be something related to the .setResultCallback.

This is how I call the activity:

Intent intent = new Intent(this, test.class);
    intent.putExtra("projectFolderID", selectedProject.getpId());
    intent.putExtra("FileName", LIKED_FILE_NAME);
    intent.putExtra("LikedArticle", userLikes);
    //startActivityForResult(intent, LIKE_FILE);
    startActivity(intent);

This is the code in the activity to create the file

public class test extends BaseActivity {

private DriveId mFolderDriveId;
private DriveId projectFolderID;
private String folderResourceID;
private DriveFolder appFolder;
private String nFile;
private LikedArticles userLikes;
private boolean printed = false;

@Override
public void onConnected(Bundle connectionHint) {
    super.onConnected(connectionHint);

    //Get Data from previous activity
    Intent intentDisplayQuery = getIntent();
    projectFolderID = DriveId.decodeFromString(intentDisplayQuery.getStringExtra("projectFolderID"));
    nFile = intentDisplayQuery.getStringExtra("FileName");
    userLikes = (LikedArticles) intentDisplayQuery.getSerializableExtra("LikedArticle");

    //Retrieve the resourceId of the project folder from decoding Id
    if (userLikes.getmLikedArticle().size()>0){
        appFolder = projectFolderID.asDriveFolder();
        appFolder.getMetadata(getGoogleApiClient())
                .setResultCallback(metadataCallback);
    }

}

final private ResultCallback<DriveResource.MetadataResult> metadataCallback = new
        ResultCallback<DriveResource.MetadataResult>() {
            @Override
            public void onResult(DriveResource.MetadataResult metadataResult) {
                if (!metadataResult.getStatus().isSuccess()) {
                    showMessage("Problem while retrieving files");
                    return;
                }
                Metadata mdb;
                try {
                    mdb = metadataResult.getMetadata();
                    mFolderDriveId = mdb.getDriveId();
                    folderResourceID = mFolderDriveId.getResourceId();
                    /*Drive.DriveApi.fetchDriveId(getGoogleApiClient(), folderResourceID)
                            .setResultCallback(idCallback);*/
                } finally { }
            }
        };

}

Thanks in advance for your help.

user274051
  • 325
  • 1
  • 12
  • I don't understand when you want to go back to previous activity. You are not calling finish()? – Ben-J Apr 14 '16 at 16:38
  • Hi @Ben-J, sorry for the late reply. I was busy. I am following this example (https://github.com/googledrive/android-demos/blob/master/app/src/main/java/com/google/android/gms/drive/sample/demo/EditContentsActivity.java). I have tried several example from there, and without calling finish() it gets back to the previous activity – user274051 Apr 14 '16 at 18:48
  • Hey, check out this [SO question]( http://stackoverflow.com/questions/22489951/how-to-use-the-setresultcallback-method) for some pointers. I hope it helps. – Mr.Rebot Apr 15 '16 at 06:37
  • Hey @Mr.Rebot. Thanks for the answer. However, I have checked the link and checked what is mentioned in the answer, but everything was right. Any other idea. – user274051 Apr 15 '16 at 09:51
  • @Ben-J I had a second thought about what you said. I included finish() when the task is done in ResultCallback. Tasks were completed and returned to the previous activity. In google examples that wasn't required but I modified their examples to make it work for my goals. In other google examples, onConnected is calling to resultCallback like that 'Drive.DriveApi.fetchDriveId(getGoogleApiClient(), EXISTING_FILE_ID) .setResultCallback(idCallback);' Does anyone know if this has an internal mechanism to go back to previous activity? Just curious now. Thanks all – user274051 Apr 15 '16 at 10:37

0 Answers0