0

I am following the Camera API instructions for Android Studio here... https://developer.android.com/guide/topics/media/camera.html#custom-camera

In it is a method that gets the name of the image file to be saved. It starts with this line:

private static File getOutputMediaFile(int type){...

Now in my app I want to be able to get the name of the most recent image saved in order to open it. However, this static method is not allowing me to copy the name to a public or non static string in order to access from another method.

I am a beginner in Java, so I'm wondering what the best way to approach this would be.

My question is, is there any harm in making this method non static?

Making it non-static still seems to work, and it allows me to access the name of the file from outside the method. However, I'm guessing that there is a good reason to make it static that I'm simply not aware of. Any ideas?

MKSchmidt
  • 13
  • 5
  • "However, this static method is not allowing me to copy the name to a public or non static string in order to access from another method" -- I'm not certain why. "I'm guessing that there is a good reason to make it static that I'm simply not aware of" -- in that sample, they did not need it to be an instance method, as it did not reference any fields or rely on any inherited methods. So, they made it static. – CommonsWare Mar 15 '18 at 17:51
  • Okay, so if you can - make it static. If you need to reference something in there - make it non-static. I'm following a Java course on Udemy, so I understand WHAT these things do, I am still uncertain WHY you might opt for one or the other. Thanks! – MKSchmidt Mar 15 '18 at 18:01
  • This has nothing much to do with Android or the camera, though. See general Java questions like [this one](https://stackoverflow.com/questions/3963983/how-and-where-to-use-static-modifier-in-java) and [this one](https://stackoverflow.com/questions/2671496/java-when-to-use-static-methods). – CommonsWare Mar 15 '18 at 18:07

0 Answers0