Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1163 - Restoring backup crash. #1164

Merged

Conversation

amrhossamdev
Copy link
Member

Fixes #1163.

Details

The issue was about the onActivityResult method. The onActivityResult method is a callback method in an Android Activity class that gets called automatically when another activity launched by the current activity exits, delivering a result back to it. This method is used to handle the result returned by the child activity. so the method was responsible for getting the data from the File picker activity about our backup-file, when we go back and do not select any file we get a null expection.

Fix

Added validation for null data that returns.

Video

Screencast.from.03-11-2024.01.44.48.PM.webm
  • Apply the AndroidStyle.xml style template to your code in Android Studio.

  • Run the unit tests with gradlew connectedObaGoogleDebugAndroidTest to make sure you didn't break anything

  • If you have multiple commits please combine them into one commit by squashing them for the initial submission of the pull request. When addressing comments on a pull request, please push a new commit per comment when possible (reviewers will squash and merge using GitHub merge tool)

@amrhossamdev
Copy link
Member Author

onActivityResult also is now deprecated i will be opening a new issue to refactor this method to follow the best practices, and I will try different test cases for saving and restoring to make sure saving and restoring are working well!

Copy link
Member

@aaronbrethorst aaronbrethorst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@@ -402,7 +402,9 @@ public void onRequestPermissionsResult(
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_CODE_RESTORE_BACKUP) {
BackupUtils.restore(this, data.getData());
if(data != null){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is super-nitpicky, but please watch your spacing:

if (data != null) {

You might also consider combining your control flow statements, either as

requestCode == REQUEST_CODE_RESTORE_BACKUP && data != null

or as

requestCode != REQUEST_CODE_RESTORE_BACKUP || data == null

for an early return.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a much better thanks for correcting me !

@aaronbrethorst aaronbrethorst merged commit 69827e7 into OneBusAway:main Mar 15, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Restoring Local Backup - Crash
2 participants