Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FragmentEvent extends Fragment {
- Button scanner;
- private final ActivityResultLauncher<ScanOptions> fragmentLauncher = registerForActivityResult(new ScanContract(),
- result -> {
- Log.i(TAG, "On Scanner Launcher.....");
- if(result.getContents() == null) {
- Toast.makeText(getContext(), "Cancelled from fragment", Toast.LENGTH_LONG).show();
- } else {
- Toast.makeText(getContext(), "Scanned from fragment: " + result.getContents(), Toast.LENGTH_LONG).show();
- }
- });
- public FragmentEvent() {
- }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.fragment_event, container, false);
- Button scan = view.findViewById(R.id.scanner);
- scan.setOnClickListener(v -> scanFromFragment());
- Log.i(TAG, "On Create .....");
- return view;
- }
- public void scanFromFragment() {
- Log.i(TAG, "On Scanner Initialization.....");
- fragmentLauncher.launch(new ScanOptions());
- }
- @Override
- public void onResume() {
- super.onResume();
- Log.i(TAG, "On Resume .....");
- }
- @Override
- public void onDestroy() {
- super.onDestroy();
- Log.i(TAG, "On Destroy .....");
- }
- @Override
- public void onPause() {
- super.onPause();
- Log.i(TAG, "On Pause .....");
- }
- @Override
- public void onStart() {
- super.onStart();
- Log.i(TAG, "On Start .....");
- }
- @Override
- public void onStop() {
- super.onStop();
- Log.i(TAG, "On Stop .....");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement