1

This question is a bit on the broader side of things so I will not provide any specific code because it will be irrelevant.

I have an app that allows the user to take photos, and hopefully videos in the future. Currently it happens as follows:

  1. The user opens a dialog inside one activity.
  2. The user can choose to take an image, which sends him to a CameraActivity (using CameraX).
  3. The user takes an image, the image is saved locally in the app files and the result code and path to the image are sent to the calling activity.
  4. The dialog overrides onActivityResult and loads the image from the internal storage and displays it.
  5. The user can choose to delete the image or cancel the entire dialog, on both cases the image needs to be removed from the storage. (The process can happen with multiple images inside the same dialog)

I wanted to ask you if it seems like a reasonable implementation or there are other architectures\android components you would recommend using. More specifically I'm worrying about the time it takes to save the image locally if I will want to increase the quality or do the same process with videos which are much heavier (I've already seen a considerable extra time if I want to save it as png instead of jpeg).

The two improvements to the system that I can think of:

  • Using something akin to ViewModel for saving the bitmap and having the data available when moving back to the dialog from the camera activity.
  • Saving the data to the cache instead on the local storage (and only save it to the local storage if the user approves in the dialog).

But I'd like to hear suggestions, are there any particular APIs that I should know about? or a recommended change to the architecture? The current system will simply be too slow for higher quality images or a video, and I'm not sure how best to improve things and also not make the app too consuming on the resources side.

user3917631
  • 119
  • 1
  • 9
  • Use one activity rather than several. You can use fragments (around since 2011) or composables (just shipped their first stabler release) for implementing individual screens. – CommonsWare Aug 11 '21 at 10:44
  • @CommonsWare Will changing to fragment have any advantage in this particular case or you're suggesting that in general? I'm mostly using fragments already, the camera was just implemented very early in the project. – user3917631 Aug 11 '21 at 11:27
  • "Will changing to fragment have any advantage in this particular case" -- your problem seems to be tied to passing this image between activities. So, if you get rid of the activity boundaries, that problem falls away. It also opens up possibilities of shared viewmodels, which are not possible between activities. – CommonsWare Aug 11 '21 at 11:42
  • A quick fix is [not best or recomended] save images or media in directories and save name/path in shared preferences while reached in particular activity check if certain preferences you saved are there. if yes use them and maybe clear file after usage and preference accordingly – MRamzan Aug 11 '21 at 12:26

0 Answers0