0

I have this code:

 public void remote(final Backup backup) {
        local(backup);
        AsyncTask.execute(new Runnable() {
            @Override
            public void run() {
                BackupSendInfo sendInfo = new BackupSendInfo()
                        .setFile(getLastBackup()) // <---
                        .setFileName(getBackupName(backup))
                        .setBackup(backup)
                        .setDeviceId(device)
                        .setApp(config.getAppName());
                fileSender.send(sendInfo);
            }
        });
    }

And this is getLastBackup method signature:

private File getLastBackup() throws BackupException;

As you can see, it throws BackupException, but I can't add throws BackuPException delcaration in remote method signature, because it is in another thread.

How should I manage this situation? I want remote method to throws BackupException

Héctor
  • 24,444
  • 35
  • 132
  • 243

1 Answers1

0

I got the solution. Maybe, it is not the best one.

I get the lastBackup outside AsyncTask, this way I can declare throws BackupException.

 public void remote(final Backup backup) throws BackupException {
        local(backup);
        final File lastBackup = getLastBackup();
        AsyncTask.execute(new Runnable() {
            @Override
            public void run() {
                BackupSendInfo sendInfo = new BackupSendInfo()
                        .setFile(lastBackup)
                        .setFileName(getBackupName(backup))
                        .setBackup(backup)
                        .setDeviceId("Desconocido") //TODO leer dispositivo del fichero deviceName
                        .setApp(config.getAppName());
                fileSender.send(sendInfo);
            }
        });
    }
Héctor
  • 24,444
  • 35
  • 132
  • 243