I'm trying to get this example code to work in Java:
https://developer.android.com/training/basics/intents/result
private final ActivityResultLauncher<Void> mTakePicture = registerForActivityResult(new TakePicturePreview(), mRegistry, new ActivityResultCallback<Bitmap>() { @Override public void onActivityResult(Bitmap thumbnail) { mThumbnailLiveData.setValue(thumbnail); } });
The example happens to be a "Fragment", and it gets mRegistry from the constructor:
public class MyFragment extends Fragment {
private final ActivityResultRegistry mRegistry;
...
public MyFragment(@NonNull ActivityResultRegistry registry) {
super();
mRegistry = registry;
}
My test case is an Activity (the "MainActivity"), not a Fragment:
public class MainActivity extends AppCompatActivity {
...
private ActivityResultRegistry activityResultRegistry;
Q: How can I initialize my registry ("activityResultRegistry") in this scenario?
It was easier than I thought:
private ActivityResultRegistry activityResultRegistry = this.getActivityResultRegistry();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With