Hello,
There is a method in fragment that gets a lot of photos and finds a face on them, then resizes the photo. If you open this fragment the first time - then everything is ok, if you press back and open again (several times), then the photos are loaded from the server but faces[i] == null . What could be the problem? Where to dig. I use Google FaceApi . At the same time, all error checking passes
fun loadImages(persons: List<Person>) { var result = ArrayList<Bitmap>() var detector = FaceDetector.Builder(activity.applicationContext) .setClassificationType(FaceDetector.FAST_MODE) .setTrackingEnabled(false) .build() for (person in persons) { if (person.image != null) { val bitmap = ImageLoader.getInstance().loadImageSync(IMAGE_HOST + person.image) ?: continue if (!detector.isOperational) Log.e("Detector", "Error") var frame = Frame.Builder().setBitmap(bitmap).build() ?: continue var faces = detector.detect(frame) ?: continue if (faces.size() > 0) { for (i in 0..faces.size()) { if (faces[i] != null) { var x = faces[i].position.x.toInt() var y = faces[i].position.y.toInt() var w = faces[i].width.toInt() var h = faces[i].height.toInt() var radius = h / 2 if (y < 0) y = 0 result.add(getCroppedBitmap(bitmap, x + w/ 2, y + h/ 2, radius)) } } } } } if (result.size > 0) showActor = true personAdapter.personal = result notifyChange() detector.release() Log.d("Detected", "TempSize" + result.size) }