Last active
September 15, 2020 18:59
-
-
Save Guilherme-HRamos/2d2533e11c1ddcb91a79341c94992682 to your computer and use it in GitHub Desktop.
Medium - Android/Java Interfaces like a Boss! - Callbacks pt l
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OpenFileHelper { | |
private final String filePath; | |
private final OpenFileHelperCallback callback; | |
public OpenFileHelper(String filePath, OpenFileHelperCallback callback) { | |
this.filePath = filePath; | |
this.callback = callback; | |
init(); | |
} | |
private void init() { | |
try { | |
openFile(); | |
} catch (Exception error) { | |
error.printStackTrace(); | |
callback.onFileOpenFailure(error); | |
} | |
} | |
private void openFile() throws IOException, FileNotFoundException { | |
File file = new File(filePath); | |
// open file code here | |
// ... | |
callback.onFileOpenSuccess(file); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface OpenFileHelperCallback { | |
void onFileOpenSuccess(File file); | |
void onFileOpenFailure(Throwable error); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok